payload 3.70.0-canary.9 → 3.71.0-internal-debug.cd77e5d
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/bin/generateImportMap/iterateGlobals.d.ts.map +1 -1
- package/dist/bin/generateImportMap/iterateGlobals.js +1 -0
- package/dist/bin/generateImportMap/iterateGlobals.js.map +1 -1
- package/dist/collections/config/types.d.ts +9 -2
- package/dist/collections/config/types.d.ts.map +1 -1
- package/dist/collections/config/types.js.map +1 -1
- package/dist/collections/operations/local/find.d.ts +7 -3
- package/dist/collections/operations/local/find.d.ts.map +1 -1
- package/dist/collections/operations/local/find.js.map +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +6 -8
- package/dist/config/sanitize.js.map +1 -1
- package/dist/config/types.d.ts +7 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/fields/baseFields/timezone/baseField.d.ts +4 -1
- package/dist/fields/baseFields/timezone/baseField.d.ts.map +1 -1
- package/dist/fields/baseFields/timezone/baseField.js +2 -1
- package/dist/fields/baseFields/timezone/baseField.js.map +1 -1
- package/dist/fields/config/client.d.ts.map +1 -1
- package/dist/fields/config/client.js +10 -0
- package/dist/fields/config/client.js.map +1 -1
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +14 -1
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/fields/config/types.d.ts +33 -2
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/index.js +1 -0
- package/dist/fields/hooks/afterRead/index.js.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts +9 -1
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/promise.js +15 -2
- package/dist/fields/hooks/afterRead/promise.js.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.d.ts +9 -1
- package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.js +2 -1
- package/dist/fields/hooks/afterRead/traverseFields.js.map +1 -1
- package/dist/globals/endpoints/findVersions.d.ts.map +1 -1
- package/dist/globals/endpoints/findVersions.js +2 -1
- package/dist/globals/endpoints/findVersions.js.map +1 -1
- package/dist/index.bundled.d.ts +108 -23
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/queues/config/types/index.d.ts +8 -10
- package/dist/queues/config/types/index.d.ts.map +1 -1
- package/dist/queues/config/types/index.js.map +1 -1
- package/dist/queues/config/types/taskTypes.d.ts +16 -6
- package/dist/queues/config/types/taskTypes.d.ts.map +1 -1
- package/dist/queues/config/types/taskTypes.js.map +1 -1
- package/dist/queues/config/types/workflowTypes.d.ts +2 -2
- package/dist/queues/config/types/workflowTypes.d.ts.map +1 -1
- package/dist/queues/config/types/workflowTypes.js.map +1 -1
- package/dist/queues/errors/index.d.ts +5 -6
- package/dist/queues/errors/index.d.ts.map +1 -1
- package/dist/queues/errors/index.js +6 -5
- package/dist/queues/errors/index.js.map +1 -1
- package/dist/queues/operations/runJobs/index.d.ts +1 -1
- package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/index.js +28 -6
- package/dist/queues/operations/runJobs/index.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js +5 -1
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js +1 -3
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js.map +1 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +14 -1
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/isolateObjectProperty.d.ts.map +1 -1
- package/dist/utilities/isolateObjectProperty.js +7 -4
- package/dist/utilities/isolateObjectProperty.js.map +1 -1
- package/dist/utilities/isolateObjectProperty.spec.js +120 -0
- package/dist/utilities/isolateObjectProperty.spec.js.map +1 -0
- package/dist/utilities/optionsAreEqual.d.ts +7 -0
- package/dist/utilities/optionsAreEqual.d.ts.map +1 -0
- package/dist/utilities/optionsAreEqual.js +35 -0
- package/dist/utilities/optionsAreEqual.js.map +1 -0
- package/dist/utilities/optionsAreEqual.spec.js +319 -0
- package/dist/utilities/optionsAreEqual.spec.js.map +1 -0
- package/dist/utilities/parseParams/index.d.ts +2 -2
- package/dist/utilities/parseParams/index.d.ts.map +1 -1
- package/dist/utilities/parseParams/index.js +3 -2
- package/dist/utilities/parseParams/index.js.map +1 -1
- package/dist/utilities/parseParams/index.spec.js +36 -0
- package/dist/utilities/parseParams/index.spec.js.map +1 -1
- package/dist/utilities/sanitizeSortParams.d.ts +2 -0
- package/dist/utilities/sanitizeSortParams.d.ts.map +1 -0
- package/dist/utilities/sanitizeSortParams.js +11 -0
- package/dist/utilities/sanitizeSortParams.js.map +1 -0
- package/dist/utilities/validateTimezones.d.ts +20 -0
- package/dist/utilities/validateTimezones.d.ts.map +1 -0
- package/dist/utilities/validateTimezones.js +76 -0
- package/dist/utilities/validateTimezones.js.map +1 -0
- package/dist/utilities/validateTimezones.spec.js +493 -0
- package/dist/utilities/validateTimezones.spec.js.map +1 -0
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as qs from 'qs-esm';
|
|
1
2
|
import { describe, it, expect } from 'vitest';
|
|
2
3
|
import { parseParams, booleanParams, numberParams } from './index.js';
|
|
3
4
|
describe('parseParams', ()=>{
|
|
@@ -134,12 +135,47 @@ describe('parseParams', ()=>{
|
|
|
134
135
|
' -updatedAt'
|
|
135
136
|
]);
|
|
136
137
|
});
|
|
138
|
+
it('should parse array of strings', ()=>{
|
|
139
|
+
const result = parseParams({
|
|
140
|
+
sort: [
|
|
141
|
+
'name',
|
|
142
|
+
'-createdAt'
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
expect(result.sort).toEqual([
|
|
146
|
+
'name',
|
|
147
|
+
'-createdAt'
|
|
148
|
+
]);
|
|
149
|
+
});
|
|
137
150
|
it('should return undefined for non-string sort values', ()=>{
|
|
138
151
|
const result = parseParams({
|
|
139
152
|
sort: 123
|
|
140
153
|
});
|
|
141
154
|
expect(result.sort).toBeUndefined();
|
|
142
155
|
});
|
|
156
|
+
it('should return undefined for array with non-string sort values', ()=>{
|
|
157
|
+
const result = parseParams({
|
|
158
|
+
sort: [
|
|
159
|
+
'name',
|
|
160
|
+
123
|
|
161
|
+
]
|
|
162
|
+
});
|
|
163
|
+
expect(result.sort).toBeUndefined();
|
|
164
|
+
});
|
|
165
|
+
it('should handle qs-esm array sort parsing', ()=>{
|
|
166
|
+
const query = qs.stringify({
|
|
167
|
+
sort: [
|
|
168
|
+
'title',
|
|
169
|
+
'-createdAt'
|
|
170
|
+
]
|
|
171
|
+
});
|
|
172
|
+
const parsed = qs.parse(query);
|
|
173
|
+
const result = parseParams(parsed);
|
|
174
|
+
expect(result.sort).toEqual([
|
|
175
|
+
'title',
|
|
176
|
+
'-createdAt'
|
|
177
|
+
]);
|
|
178
|
+
});
|
|
143
179
|
it('should return undefined for null sort values', ()=>{
|
|
144
180
|
const result = parseParams({
|
|
145
181
|
sort: null
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utilities/parseParams/index.spec.ts"],"sourcesContent":["import { describe, it, expect } from 'vitest'\nimport { parseParams, booleanParams, numberParams } from './index.js'\n\ndescribe('parseParams', () => {\n describe('boolean parameters', () => {\n booleanParams.forEach((param) => {\n describe(param, () => {\n it('should parse string \"true\" to boolean true', () => {\n const result = parseParams({ [param]: 'true' })\n expect(result[param]).toBe(true)\n })\n\n it('should parse string \"false\" to boolean false', () => {\n const result = parseParams({ [param]: 'false' })\n expect(result[param]).toBe(false)\n })\n\n it('should parse boolean true to boolean true', () => {\n const result = parseParams({ [param]: true })\n expect(result[param]).toBe(true)\n })\n\n it('should parse boolean false to boolean false', () => {\n const result = parseParams({ [param]: false })\n expect(result[param]).toBe(false)\n })\n\n it('should return undefined for truthy strings (not exact \"true\")', () => {\n const result = parseParams({ [param]: '1' })\n expect(result[param]).toBeUndefined()\n })\n\n it('should return undefined for falsy strings (not exact \"false\")', () => {\n const result = parseParams({ [param]: '0' })\n expect(result[param]).toBeUndefined()\n })\n\n it('should return undefined for empty string', () => {\n const result = parseParams({ [param]: '' })\n expect(result[param]).toBeUndefined()\n })\n })\n })\n })\n\n describe('number parameters', () => {\n numberParams.forEach((param) => {\n describe(param, () => {\n it('should parse valid number string to number', () => {\n const result = parseParams({ [param]: '42' })\n expect(result[param]).toBe(42)\n })\n\n it('should parse zero string to zero', () => {\n const result = parseParams({ [param]: '0' })\n expect(result[param]).toBe(0)\n })\n\n it('should parse negative number string to negative number', () => {\n const result = parseParams({ [param]: '-5' })\n expect(result[param]).toBe(-5)\n })\n\n it('should parse decimal number string to decimal number', () => {\n const result = parseParams({ [param]: '3.14' })\n expect(result[param]).toBe(3.14)\n })\n\n it('should not parse invalid number strings', () => {\n const result = parseParams({ [param]: 'not-a-number' })\n expect(result[param]).toBe('not-a-number') // remains as string\n })\n\n it('should not parse empty string', () => {\n const result = parseParams({ [param]: '' })\n expect(result[param]).toBe('') // remains as string\n })\n\n it('should handle already numeric values', () => {\n const result = parseParams({ [param]: 123 })\n expect(result[param]).toBe(123)\n })\n })\n })\n })\n\n describe('sort parameter', () => {\n it('should parse comma-separated string to array', () => {\n const result = parseParams({ sort: 'name,createdAt,-updatedAt' })\n expect(result.sort).toEqual(['name', 'createdAt', '-updatedAt'])\n })\n\n it('should parse single value string to array with one element', () => {\n const result = parseParams({ sort: 'name' })\n expect(result.sort).toEqual(['name'])\n })\n\n it('should handle empty string', () => {\n const result = parseParams({ sort: '' })\n expect(result.sort).toEqual([''])\n })\n\n it('should handle comma-separated string with spaces', () => {\n const result = parseParams({ sort: 'name, createdAt , -updatedAt' })\n expect(result.sort).toEqual(['name', ' createdAt ', ' -updatedAt'])\n })\n\n it('should return undefined for non-string sort values', () => {\n const result = parseParams({ sort: 123 as any })\n expect(result.sort).toBeUndefined()\n })\n\n it('should return undefined for null sort values', () => {\n const result = parseParams({ sort: null as any })\n expect(result.sort).toBeUndefined()\n })\n })\n\n describe('data parameter', () => {\n it('should parse valid JSON string', () => {\n const data = { name: 'test', value: 42 }\n const result = parseParams({ data: JSON.stringify(data) })\n expect(result.data).toEqual(data)\n })\n\n it('should parse empty object JSON string', () => {\n const result = parseParams({ data: '{}' })\n expect(result.data).toEqual({})\n })\n\n it('should parse array JSON string', () => {\n const data = [1, 2, 3]\n const result = parseParams({ data: JSON.stringify(data) })\n expect(result.data).toEqual(data)\n })\n\n it('should not process empty string', () => {\n const result = parseParams({ data: '' })\n expect(result.data).toBe('') // empty string is not processed, remains as string\n })\n\n it('should throw error for invalid JSON', () => {\n expect(() => {\n parseParams({ data: 'invalid-json' })\n }).toThrow()\n })\n\n it('should not process non-string data values', () => {\n const result = parseParams({ data: { already: 'parsed' } as any })\n expect(result.data).toEqual({ already: 'parsed' })\n })\n })\n\n describe('special parameters', () => {\n it('should handle populate parameter', () => {\n const result = parseParams({ populate: 'field1,field2' })\n expect(result).toHaveProperty('populate')\n // Note: actual sanitization logic is tested in sanitizePopulateParam tests\n })\n\n it('should handle select parameter', () => {\n const result = parseParams({ select: 'field1,field2' })\n expect(result).toHaveProperty('select')\n // Note: actual sanitization logic is tested in sanitizeSelectParam tests\n })\n\n it('should handle joins parameter', () => {\n const joins = { collection: 'posts' }\n const result = parseParams({ joins })\n expect(result).toHaveProperty('joins')\n // Note: actual sanitization logic is tested in sanitizeJoinParams tests\n })\n })\n\n describe('selectedLocales parameter', () => {\n it('should pass through selectedLocales as-is', () => {\n const selectedLocales = 'en,es,fr'\n const result = parseParams({ selectedLocales })\n expect(result.selectedLocales).toBe(selectedLocales)\n })\n })\n\n describe('publishSpecificLocale parameter', () => {\n it('should pass through publishSpecificLocale as-is', () => {\n const publishSpecificLocale = 'en'\n const result = parseParams({ publishSpecificLocale })\n expect(result.publishSpecificLocale).toBe(publishSpecificLocale)\n })\n })\n\n describe('field parameter', () => {\n it('should pass through field as-is', () => {\n const field = 'myField'\n const result = parseParams({ field })\n expect(result.field).toBe(field)\n })\n })\n\n describe('where parameter', () => {\n it('should pass through where as-is', () => {\n const where = { name: { equals: 'test' } }\n const result = parseParams({ where })\n expect(result.where).toBe(where)\n })\n })\n\n describe('edge cases', () => {\n it('should handle empty params object', () => {\n const result = parseParams({})\n expect(result).toEqual({})\n })\n\n it('should throw error for null params (current implementation bug)', () => {\n expect(() => {\n parseParams(null as any)\n }).toThrow(TypeError)\n })\n\n it('should throw error for undefined params (current implementation bug)', () => {\n expect(() => {\n parseParams(undefined as any)\n }).toThrow(TypeError)\n })\n\n it('should preserve unknown parameters', () => {\n const result = parseParams({ customParam: 'customValue' })\n expect(result.customParam).toBe('customValue')\n })\n\n it('should handle mixed parameter types', () => {\n const result = parseParams({\n draft: 'true',\n depth: '5',\n sort: 'name,createdAt',\n data: '{\"test\": true}',\n customParam: 'custom',\n })\n\n expect(result.draft).toBe(true)\n expect(result.depth).toBe(5)\n expect(result.sort).toEqual(['name', 'createdAt'])\n expect(result.data).toEqual({ test: true })\n expect(result.customParam).toBe('custom')\n })\n })\n\n describe('parameter preservation', () => {\n it('should not modify parameters that are not in known lists', () => {\n const params = {\n unknownBoolean: 'true',\n unknownNumber: '42',\n unknownString: 'test',\n }\n const result = parseParams(params)\n\n expect(result.unknownBoolean).toBe('true') // should remain string\n expect(result.unknownNumber).toBe('42') // should remain string\n expect(result.unknownString).toBe('test')\n })\n\n it('should only process parameters that exist in the input', () => {\n const result = parseParams({ draft: 'true' })\n\n expect(result.draft).toBe(true)\n expect(result).not.toHaveProperty('autosave')\n expect(result).not.toHaveProperty('depth')\n expect(result).not.toHaveProperty('sort')\n })\n })\n})\n"],"names":["describe","it","expect","parseParams","booleanParams","numberParams","forEach","param","result","toBe","toBeUndefined","sort","toEqual","data","name","value","JSON","stringify","toThrow","already","populate","toHaveProperty","select","joins","collection","selectedLocales","publishSpecificLocale","field","where","equals","TypeError","undefined","customParam","draft","depth","test","params","unknownBoolean","unknownNumber","unknownString","not"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,QAAQ,SAAQ;AAC7C,SAASC,WAAW,EAAEC,aAAa,EAAEC,YAAY,QAAQ,aAAY;AAErEL,SAAS,eAAe;IACtBA,SAAS,sBAAsB;QAC7BI,cAAcE,OAAO,CAAC,CAACC;YACrBP,SAASO,OAAO;gBACdN,GAAG,8CAA8C;oBAC/C,MAAMO,SAASL,YAAY;wBAAE,CAACI,MAAM,EAAE;oBAAO;oBAC7CL,OAAOM,MAAM,CAACD,MAAM,EAAEE,IAAI,CAAC;gBAC7B;gBAEAR,GAAG,gDAAgD;oBACjD,MAAMO,SAASL,YAAY;wBAAE,CAACI,MAAM,EAAE;oBAAQ;oBAC9CL,OAAOM,MAAM,CAACD,MAAM,EAAEE,IAAI,CAAC;gBAC7B;gBAEAR,GAAG,6CAA6C;oBAC9C,MAAMO,SAASL,YAAY;wBAAE,CAACI,MAAM,EAAE;oBAAK;oBAC3CL,OAAOM,MAAM,CAACD,MAAM,EAAEE,IAAI,CAAC;gBAC7B;gBAEAR,GAAG,+CAA+C;oBAChD,MAAMO,SAASL,YAAY;wBAAE,CAACI,MAAM,EAAE;oBAAM;oBAC5CL,OAAOM,MAAM,CAACD,MAAM,EAAEE,IAAI,CAAC;gBAC7B;gBAEAR,GAAG,iEAAiE;oBAClE,MAAMO,SAASL,YAAY;wBAAE,CAACI,MAAM,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OAAO;gBACPvB,MAAM;gBACNE,MAAM;gBACNmB,aAAa;YACf;YAEA9B,OAAOM,OAAOyB,KAAK,EAAExB,IAAI,CAAC;YAC1BP,OAAOM,OAAO0B,KAAK,EAAEzB,IAAI,CAAC;YAC1BP,OAAOM,OAAOG,IAAI,EAAEC,OAAO,CAAC;gBAAC;gBAAQ;aAAY;YACjDV,OAAOM,OAAOK,IAAI,EAAED,OAAO,CAAC;gBAAEuB,MAAM;YAAK;YACzCjC,OAAOM,OAAOwB,WAAW,EAAEvB,IAAI,CAAC;QAClC;IACF;IAEAT,SAAS,0BAA0B;QACjCC,GAAG,4DAA4D;YAC7D,MAAMmC,SAAS;gBACbC,gBAAgB;gBAChBC,eAAe;gBACfC,eAAe;YACjB;YACA,MAAM/B,SAASL,YAAYiC;YAE3BlC,OAAOM,OAAO6B,cAAc,EAAE5B,IAAI,CAAC,SAAQ,uBAAuB;YAClEP,OAAOM,OAAO8B,aAAa,EAAE7B,IAAI,CAAC,OAAM,uBAAuB;YAC/DP,OAAOM,OAAO+B,aAAa,EAAE9B,IAAI,CAAC;QACpC;QAEAR,GAAG,0DAA0D;YAC3D,MAAMO,SAASL,YAAY;gBAAE8B,OAAO;YAAO;YAE3C/B,OAAOM,OAAOyB,KAAK,EAAExB,IAAI,CAAC;YAC1BP,OAAOM,QAAQgC,GAAG,CAACnB,cAAc,CAAC;YAClCnB,OAAOM,QAAQgC,GAAG,CAACnB,cAAc,CAAC;YAClCnB,OAAOM,QAAQgC,GAAG,CAACnB,cAAc,CAAC;QACpC;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/utilities/parseParams/index.spec.ts"],"sourcesContent":["import * as qs from 'qs-esm'\nimport { describe, it, expect } from 'vitest'\nimport { parseParams, booleanParams, numberParams } from './index.js'\n\ndescribe('parseParams', () => {\n describe('boolean parameters', () => {\n booleanParams.forEach((param) => {\n describe(param, () => {\n it('should parse string \"true\" to boolean true', () => {\n const result = parseParams({ [param]: 'true' })\n expect(result[param]).toBe(true)\n })\n\n it('should parse string \"false\" to boolean false', () => {\n const result = parseParams({ [param]: 'false' })\n expect(result[param]).toBe(false)\n })\n\n it('should parse boolean true to boolean true', () => {\n const result = parseParams({ [param]: true })\n expect(result[param]).toBe(true)\n })\n\n it('should parse boolean false to boolean false', () => {\n const result = parseParams({ [param]: false })\n expect(result[param]).toBe(false)\n })\n\n it('should return undefined for truthy strings (not exact \"true\")', () => {\n const result = parseParams({ [param]: '1' })\n expect(result[param]).toBeUndefined()\n })\n\n it('should return undefined for falsy strings (not exact \"false\")', () => {\n const result = parseParams({ [param]: '0' })\n expect(result[param]).toBeUndefined()\n })\n\n it('should return undefined for empty string', () => {\n const result = parseParams({ [param]: '' })\n expect(result[param]).toBeUndefined()\n })\n })\n })\n })\n\n describe('number parameters', () => {\n numberParams.forEach((param) => {\n describe(param, () => {\n it('should parse valid number string to number', () => {\n const result = parseParams({ [param]: '42' })\n expect(result[param]).toBe(42)\n })\n\n it('should parse zero string to zero', () => {\n const result = parseParams({ [param]: '0' })\n expect(result[param]).toBe(0)\n })\n\n it('should parse negative number string to negative number', () => {\n const result = parseParams({ [param]: '-5' })\n expect(result[param]).toBe(-5)\n })\n\n it('should parse decimal number string to decimal number', () => {\n const result = parseParams({ [param]: '3.14' })\n expect(result[param]).toBe(3.14)\n })\n\n it('should not parse invalid number strings', () => {\n const result = parseParams({ [param]: 'not-a-number' })\n expect(result[param]).toBe('not-a-number') // remains as string\n })\n\n it('should not parse empty string', () => {\n const result = parseParams({ [param]: '' })\n expect(result[param]).toBe('') // remains as string\n })\n\n it('should handle already numeric values', () => {\n const result = parseParams({ [param]: 123 })\n expect(result[param]).toBe(123)\n })\n })\n })\n })\n\n describe('sort parameter', () => {\n it('should parse comma-separated string to array', () => {\n const result = parseParams({ sort: 'name,createdAt,-updatedAt' })\n expect(result.sort).toEqual(['name', 'createdAt', '-updatedAt'])\n })\n\n it('should parse single value string to array with one element', () => {\n const result = parseParams({ sort: 'name' })\n expect(result.sort).toEqual(['name'])\n })\n\n it('should handle empty string', () => {\n const result = parseParams({ sort: '' })\n expect(result.sort).toEqual([''])\n })\n\n it('should handle comma-separated string with spaces', () => {\n const result = parseParams({ sort: 'name, createdAt , -updatedAt' })\n expect(result.sort).toEqual(['name', ' createdAt ', ' -updatedAt'])\n })\n\n it('should parse array of strings', () => {\n const result = parseParams({ sort: ['name', '-createdAt'] })\n expect(result.sort).toEqual(['name', '-createdAt'])\n })\n\n it('should return undefined for non-string sort values', () => {\n const result = parseParams({ sort: 123 as any })\n expect(result.sort).toBeUndefined()\n })\n\n it('should return undefined for array with non-string sort values', () => {\n const result = parseParams({ sort: ['name', 123] as any })\n expect(result.sort).toBeUndefined()\n })\n\n it('should handle qs-esm array sort parsing', () => {\n const query = qs.stringify({ sort: ['title', '-createdAt'] })\n const parsed = qs.parse(query)\n const result = parseParams(parsed)\n expect(result.sort).toEqual(['title', '-createdAt'])\n })\n\n it('should return undefined for null sort values', () => {\n const result = parseParams({ sort: null as any })\n expect(result.sort).toBeUndefined()\n })\n })\n\n describe('data parameter', () => {\n it('should parse valid JSON string', () => {\n const data = { name: 'test', value: 42 }\n const result = parseParams({ data: JSON.stringify(data) })\n expect(result.data).toEqual(data)\n })\n\n it('should parse empty object JSON string', () => {\n const result = parseParams({ data: '{}' })\n expect(result.data).toEqual({})\n })\n\n it('should parse array JSON string', () => {\n const data = [1, 2, 3]\n const result = parseParams({ data: JSON.stringify(data) })\n expect(result.data).toEqual(data)\n })\n\n it('should not process empty string', () => {\n const result = parseParams({ data: '' })\n expect(result.data).toBe('') // empty string is not processed, remains as string\n })\n\n it('should throw error for invalid JSON', () => {\n expect(() => {\n parseParams({ data: 'invalid-json' })\n }).toThrow()\n })\n\n it('should not process non-string data values', () => {\n const result = parseParams({ data: { already: 'parsed' } as any })\n expect(result.data).toEqual({ already: 'parsed' })\n })\n })\n\n describe('special parameters', () => {\n it('should handle populate parameter', () => {\n const result = parseParams({ populate: 'field1,field2' })\n expect(result).toHaveProperty('populate')\n // Note: actual sanitization logic is tested in sanitizePopulateParam tests\n })\n\n it('should handle select parameter', () => {\n const result = parseParams({ select: 'field1,field2' })\n expect(result).toHaveProperty('select')\n // Note: actual sanitization logic is tested in sanitizeSelectParam tests\n })\n\n it('should handle joins parameter', () => {\n const joins = { collection: 'posts' }\n const result = parseParams({ joins })\n expect(result).toHaveProperty('joins')\n // Note: actual sanitization logic is tested in sanitizeJoinParams tests\n })\n })\n\n describe('selectedLocales parameter', () => {\n it('should pass through selectedLocales as-is', () => {\n const selectedLocales = 'en,es,fr'\n const result = parseParams({ selectedLocales })\n expect(result.selectedLocales).toBe(selectedLocales)\n })\n })\n\n describe('publishSpecificLocale parameter', () => {\n it('should pass through publishSpecificLocale as-is', () => {\n const publishSpecificLocale = 'en'\n const result = parseParams({ publishSpecificLocale })\n expect(result.publishSpecificLocale).toBe(publishSpecificLocale)\n })\n })\n\n describe('field parameter', () => {\n it('should pass through field as-is', () => {\n const field = 'myField'\n const result = parseParams({ field })\n expect(result.field).toBe(field)\n })\n })\n\n describe('where parameter', () => {\n it('should pass through where as-is', () => {\n const where = { name: { equals: 'test' } }\n const result = parseParams({ where })\n expect(result.where).toBe(where)\n })\n })\n\n describe('edge cases', () => {\n it('should handle empty params object', () => {\n const result = parseParams({})\n expect(result).toEqual({})\n })\n\n it('should throw error for null params (current implementation bug)', () => {\n expect(() => {\n parseParams(null as any)\n }).toThrow(TypeError)\n })\n\n it('should throw error for undefined params (current implementation bug)', () => {\n expect(() => {\n parseParams(undefined as any)\n }).toThrow(TypeError)\n })\n\n it('should preserve unknown parameters', () => {\n const result = parseParams({ customParam: 'customValue' })\n expect(result.customParam).toBe('customValue')\n })\n\n it('should handle mixed parameter types', () => {\n const result = parseParams({\n draft: 'true',\n depth: '5',\n sort: 'name,createdAt',\n data: '{\"test\": true}',\n customParam: 'custom',\n })\n\n expect(result.draft).toBe(true)\n expect(result.depth).toBe(5)\n expect(result.sort).toEqual(['name', 'createdAt'])\n expect(result.data).toEqual({ test: true })\n expect(result.customParam).toBe('custom')\n })\n })\n\n describe('parameter preservation', () => {\n it('should not modify parameters that are not in known lists', () => {\n const params = {\n unknownBoolean: 'true',\n unknownNumber: '42',\n unknownString: 'test',\n }\n const result = parseParams(params)\n\n expect(result.unknownBoolean).toBe('true') // should remain string\n expect(result.unknownNumber).toBe('42') // should remain string\n expect(result.unknownString).toBe('test')\n })\n\n it('should only process parameters that exist in the input', () => {\n const result = parseParams({ draft: 'true' })\n\n expect(result.draft).toBe(true)\n expect(result).not.toHaveProperty('autosave')\n expect(result).not.toHaveProperty('depth')\n expect(result).not.toHaveProperty('sort')\n })\n })\n})\n"],"names":["qs","describe","it","expect","parseParams","booleanParams","numberParams","forEach","param","result","toBe","toBeUndefined","sort","toEqual","query","stringify","parsed","parse","data","name","value","JSON","toThrow","already","populate","toHaveProperty","select","joins","collection","selectedLocales","publishSpecificLocale","field","where","equals","TypeError","undefined","customParam","draft","depth","test","params","unknownBoolean","unknownNumber","unknownString","not"],"mappings":"AAAA,YAAYA,QAAQ,SAAQ;AAC5B,SAASC,QAAQ,EAAEC,EAAE,EAAEC,MAAM,QAAQ,SAAQ;AAC7C,SAASC,WAAW,EAAEC,aAAa,EAAEC,YAAY,QAAQ,aAAY;AAErEL,SAAS,eAAe;IACtBA,SAAS,sBAAsB;QAC7BI,cAAcE,OAAO,CAAC,CAACC;YACrBP,SAASO,OAAO;gBACdN,GAAG,8CAA8C;oBAC/C,MAAMO,SAASL,YAAY;wBAAE,CAACI,MAAM,EAAE;oBAAO;oBAC7CL,OAAOM,MAAM,CAACD,MAAM,EAAEE,IAAI,CAAC;gBAC7B;gBAEAR,GAAG,gDAAgD;oBACjD,MAAMO,SAASL,YAAY;wBAAE,CAACI,MAAM,EAAE;oBAAQ;oBAC9CL,OAAOM,MAAM,CAACD,MAAM,EAAEE,IAAI,CAAC;gBAC7B;gBAEAR,GAAG,6CAA6C;oBAC9C,MAAMO,SAASL,YAAY;wBAAE,CAACI,MAAM,EAA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GAAG,4DAA4D;YAC7D,MAAMsC,SAAS;gBACbC,gBAAgB;gBAChBC,eAAe;gBACfC,eAAe;YACjB;YACA,MAAMlC,SAASL,YAAYoC;YAE3BrC,OAAOM,OAAOgC,cAAc,EAAE/B,IAAI,CAAC,SAAQ,uBAAuB;YAClEP,OAAOM,OAAOiC,aAAa,EAAEhC,IAAI,CAAC,OAAM,uBAAuB;YAC/DP,OAAOM,OAAOkC,aAAa,EAAEjC,IAAI,CAAC;QACpC;QAEAR,GAAG,0DAA0D;YAC3D,MAAMO,SAASL,YAAY;gBAAEiC,OAAO;YAAO;YAE3ClC,OAAOM,OAAO4B,KAAK,EAAE3B,IAAI,CAAC;YAC1BP,OAAOM,QAAQmC,GAAG,CAACnB,cAAc,CAAC;YAClCtB,OAAOM,QAAQmC,GAAG,CAACnB,cAAc,CAAC;YAClCtB,OAAOM,QAAQmC,GAAG,CAACnB,cAAc,CAAC;QACpC;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeSortParams.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizeSortParams.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,SAAU,OAAO,KAAG,MAAM,EAAE,GAAG,SAU7D,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const sanitizeSortParams = (sort)=>{
|
|
2
|
+
if (typeof sort === 'string') {
|
|
3
|
+
return sort.split(',');
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(sort) && sort.every((value)=>typeof value === 'string')) {
|
|
6
|
+
return sort;
|
|
7
|
+
}
|
|
8
|
+
return undefined;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=sanitizeSortParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/sanitizeSortParams.ts"],"sourcesContent":["export const sanitizeSortParams = (sort: unknown): string[] | undefined => {\n if (typeof sort === 'string') {\n return sort.split(',')\n }\n\n if (Array.isArray(sort) && sort.every((value) => typeof value === 'string')) {\n return sort\n }\n\n return undefined\n}\n"],"names":["sanitizeSortParams","sort","split","Array","isArray","every","value","undefined"],"mappings":"AAAA,OAAO,MAAMA,qBAAqB,CAACC;IACjC,IAAI,OAAOA,SAAS,UAAU;QAC5B,OAAOA,KAAKC,KAAK,CAAC;IACpB;IAEA,IAAIC,MAAMC,OAAO,CAACH,SAASA,KAAKI,KAAK,CAAC,CAACC,QAAU,OAAOA,UAAU,WAAW;QAC3E,OAAOL;IACT;IAEA,OAAOM;AACT,EAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Timezone } from '../config/types.js';
|
|
2
|
+
type ValidateTimezonesArgs = {
|
|
3
|
+
/**
|
|
4
|
+
* The source of the timezones for error messaging
|
|
5
|
+
*/
|
|
6
|
+
source?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Array of timezones to validate
|
|
9
|
+
*/
|
|
10
|
+
timezones: Timezone[] | undefined;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Validates that all provided timezones are supported by the current runtime's Intl API.
|
|
14
|
+
* Uses both Intl.DateTimeFormat and Intl.supportedValuesOf for comprehensive validation.
|
|
15
|
+
*
|
|
16
|
+
* @throws InvalidConfiguration if an unsupported timezone is found
|
|
17
|
+
*/
|
|
18
|
+
export declare const validateTimezones: ({ source, timezones }: ValidateTimezonesArgs) => void;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=validateTimezones.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateTimezones.d.ts","sourceRoot":"","sources":["../../src/utilities/validateTimezones.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAIlD,KAAK,qBAAqB,GAAG;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAA;CAClC,CAAA;AAoED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,0BAA2B,qBAAqB,KAAG,IAahF,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { InvalidConfiguration } from '../errors/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a UTC offset string.
|
|
4
|
+
* Only supports the ±HH:mm format (e.g., +05:30, -08:00).
|
|
5
|
+
*
|
|
6
|
+
* Valid ranges: hours -12 to +14, minutes 0-59
|
|
7
|
+
*
|
|
8
|
+
* @returns true if the offset is valid
|
|
9
|
+
*/ const isValidUtcOffset = (value)=>{
|
|
10
|
+
// Strict format check: only ±HH:mm
|
|
11
|
+
const match = value.match(/^([+-])(\d{2}):(\d{2})$/);
|
|
12
|
+
if (!match) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const sign = match[1] === '+' ? 1 : -1;
|
|
16
|
+
const hours = parseInt(match[2], 10);
|
|
17
|
+
const minutes = parseInt(match[3], 10);
|
|
18
|
+
// Minutes must be 0-59
|
|
19
|
+
if (minutes > 59) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
// Valid range: -12:00 (-720 min) to +14:00 (+840 min)
|
|
23
|
+
const totalMinutes = sign * (hours * 60 + minutes);
|
|
24
|
+
return totalMinutes >= -720 && totalMinutes <= 840;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a timezone is supported by the current runtime.
|
|
28
|
+
* Supports both IANA timezone names and UTC offset formats.
|
|
29
|
+
*
|
|
30
|
+
* For IANA names: Uses Intl.DateTimeFormat and Intl.supportedValuesOf
|
|
31
|
+
* For UTC offsets: Uses native Date API to validate (±HH:mm format only)
|
|
32
|
+
*/ const isTimezoneSupported = (timezoneValue)=>{
|
|
33
|
+
// UTC is always supported
|
|
34
|
+
if (timezoneValue === 'UTC') {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
// Check if it's a UTC offset format (starts with + or -)
|
|
38
|
+
if (timezoneValue.startsWith('+') || timezoneValue.startsWith('-')) {
|
|
39
|
+
return isValidUtcOffset(timezoneValue);
|
|
40
|
+
}
|
|
41
|
+
// For IANA timezone names, use Intl.DateTimeFormat as primary check
|
|
42
|
+
try {
|
|
43
|
+
new Intl.DateTimeFormat('en-US', {
|
|
44
|
+
timeZone: timezoneValue
|
|
45
|
+
});
|
|
46
|
+
return true;
|
|
47
|
+
} catch {
|
|
48
|
+
// DateTimeFormat failed, timezone is not supported
|
|
49
|
+
}
|
|
50
|
+
// Secondary check: verify against supportedValuesOf if available
|
|
51
|
+
if (typeof Intl.supportedValuesOf === 'function') {
|
|
52
|
+
const supportedTimezones = Intl.supportedValuesOf('timeZone');
|
|
53
|
+
if (supportedTimezones.includes(timezoneValue)) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Validates that all provided timezones are supported by the current runtime's Intl API.
|
|
61
|
+
* Uses both Intl.DateTimeFormat and Intl.supportedValuesOf for comprehensive validation.
|
|
62
|
+
*
|
|
63
|
+
* @throws InvalidConfiguration if an unsupported timezone is found
|
|
64
|
+
*/ export const validateTimezones = ({ source, timezones })=>{
|
|
65
|
+
if (!timezones?.length) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const timezone of timezones){
|
|
69
|
+
if (!isTimezoneSupported(timezone.value)) {
|
|
70
|
+
const sourceText = source ? ` in ${source}` : '';
|
|
71
|
+
throw new InvalidConfiguration(`Timezone ${timezone.value}${sourceText} is not supported by the current runtime via the Intl API.`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=validateTimezones.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/validateTimezones.ts"],"sourcesContent":["import type { Timezone } from '../config/types.js'\n\nimport { InvalidConfiguration } from '../errors/index.js'\n\ntype ValidateTimezonesArgs = {\n /**\n * The source of the timezones for error messaging\n */\n source?: string\n /**\n * Array of timezones to validate\n */\n timezones: Timezone[] | undefined\n}\n\n/**\n * Validates a UTC offset string.\n * Only supports the ±HH:mm format (e.g., +05:30, -08:00).\n *\n * Valid ranges: hours -12 to +14, minutes 0-59\n *\n * @returns true if the offset is valid\n */\nconst isValidUtcOffset = (value: string): boolean => {\n // Strict format check: only ±HH:mm\n const match = value.match(/^([+-])(\\d{2}):(\\d{2})$/)\n if (!match) {\n return false\n }\n\n const sign = match[1] === '+' ? 1 : -1\n const hours = parseInt(match[2]!, 10)\n const minutes = parseInt(match[3]!, 10)\n\n // Minutes must be 0-59\n if (minutes > 59) {\n return false\n }\n\n // Valid range: -12:00 (-720 min) to +14:00 (+840 min)\n const totalMinutes = sign * (hours * 60 + minutes)\n return totalMinutes >= -720 && totalMinutes <= 840\n}\n\n/**\n * Checks if a timezone is supported by the current runtime.\n * Supports both IANA timezone names and UTC offset formats.\n *\n * For IANA names: Uses Intl.DateTimeFormat and Intl.supportedValuesOf\n * For UTC offsets: Uses native Date API to validate (±HH:mm format only)\n */\nconst isTimezoneSupported = (timezoneValue: string): boolean => {\n // UTC is always supported\n if (timezoneValue === 'UTC') {\n return true\n }\n\n // Check if it's a UTC offset format (starts with + or -)\n if (timezoneValue.startsWith('+') || timezoneValue.startsWith('-')) {\n return isValidUtcOffset(timezoneValue)\n }\n\n // For IANA timezone names, use Intl.DateTimeFormat as primary check\n try {\n new Intl.DateTimeFormat('en-US', { timeZone: timezoneValue })\n return true\n } catch {\n // DateTimeFormat failed, timezone is not supported\n }\n\n // Secondary check: verify against supportedValuesOf if available\n if (typeof Intl.supportedValuesOf === 'function') {\n const supportedTimezones = Intl.supportedValuesOf('timeZone')\n if (supportedTimezones.includes(timezoneValue)) {\n return true\n }\n }\n\n return false\n}\n\n/**\n * Validates that all provided timezones are supported by the current runtime's Intl API.\n * Uses both Intl.DateTimeFormat and Intl.supportedValuesOf for comprehensive validation.\n *\n * @throws InvalidConfiguration if an unsupported timezone is found\n */\nexport const validateTimezones = ({ source, timezones }: ValidateTimezonesArgs): void => {\n if (!timezones?.length) {\n return\n }\n\n for (const timezone of timezones) {\n if (!isTimezoneSupported(timezone.value)) {\n const sourceText = source ? ` in ${source}` : ''\n throw new InvalidConfiguration(\n `Timezone ${timezone.value}${sourceText} is not supported by the current runtime via the Intl API.`,\n )\n }\n }\n}\n"],"names":["InvalidConfiguration","isValidUtcOffset","value","match","sign","hours","parseInt","minutes","totalMinutes","isTimezoneSupported","timezoneValue","startsWith","Intl","DateTimeFormat","timeZone","supportedValuesOf","supportedTimezones","includes","validateTimezones","source","timezones","length","timezone","sourceText"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,qBAAoB;AAazD;;;;;;;CAOC,GACD,MAAMC,mBAAmB,CAACC;IACxB,mCAAmC;IACnC,MAAMC,QAAQD,MAAMC,KAAK,CAAC;IAC1B,IAAI,CAACA,OAAO;QACV,OAAO;IACT;IAEA,MAAMC,OAAOD,KAAK,CAAC,EAAE,KAAK,MAAM,IAAI,CAAC;IACrC,MAAME,QAAQC,SAASH,KAAK,CAAC,EAAE,EAAG;IAClC,MAAMI,UAAUD,SAASH,KAAK,CAAC,EAAE,EAAG;IAEpC,uBAAuB;IACvB,IAAII,UAAU,IAAI;QAChB,OAAO;IACT;IAEA,sDAAsD;IACtD,MAAMC,eAAeJ,OAAQC,CAAAA,QAAQ,KAAKE,OAAM;IAChD,OAAOC,gBAAgB,CAAC,OAAOA,gBAAgB;AACjD;AAEA;;;;;;CAMC,GACD,MAAMC,sBAAsB,CAACC;IAC3B,0BAA0B;IAC1B,IAAIA,kBAAkB,OAAO;QAC3B,OAAO;IACT;IAEA,yDAAyD;IACzD,IAAIA,cAAcC,UAAU,CAAC,QAAQD,cAAcC,UAAU,CAAC,MAAM;QAClE,OAAOV,iBAAiBS;IAC1B;IAEA,oEAAoE;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