@strapi/utils 5.59.0 → 5.61.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.
- package/dist/content-types.mjs +18 -18
- package/dist/content-types.mjs.map +1 -1
- package/dist/convert-query-params.mjs +18 -18
- package/dist/convert-query-params.mjs.map +1 -1
- package/dist/env-helper.mjs +9 -9
- package/dist/env-helper.mjs.map +1 -1
- package/dist/parse-type.js +2 -3
- package/dist/parse-type.js.map +1 -1
- package/dist/parse-type.mjs +3 -3
- package/dist/parse-type.mjs.map +1 -1
- package/dist/primitives/objects.mjs +4 -4
- package/dist/primitives/objects.mjs.map +1 -1
- package/dist/primitives/strings.mjs +6 -6
- package/dist/primitives/strings.mjs.map +1 -1
- package/dist/provider-factory.d.ts.map +1 -1
- package/dist/provider-factory.js +14 -6
- package/dist/provider-factory.js.map +1 -1
- package/dist/provider-factory.mjs +14 -6
- package/dist/provider-factory.mjs.map +1 -1
- package/dist/sort-query.mjs +2 -2
- package/dist/sort-query.mjs.map +1 -1
- package/dist/yup.mjs +5 -5
- package/dist/yup.mjs.map +1 -1
- package/package.json +6 -6
package/dist/provider-factory.js
CHANGED
|
@@ -19,18 +19,26 @@ var hooks = require('./hooks.js');
|
|
|
19
19
|
const { throwOnDuplicates = true } = options;
|
|
20
20
|
const state = {
|
|
21
21
|
hooks: createProviderHooksMap(),
|
|
22
|
-
registry: new Map()
|
|
22
|
+
registry: new Map(),
|
|
23
|
+
// Keys whose registration is awaiting the willRegister hook
|
|
24
|
+
pendingKeys: new Set()
|
|
23
25
|
};
|
|
24
26
|
return {
|
|
25
27
|
hooks: state.hooks,
|
|
26
28
|
async register (key, item) {
|
|
27
|
-
if (throwOnDuplicates && this.has(key)) {
|
|
29
|
+
if (throwOnDuplicates && (this.has(key) || state.pendingKeys.has(key))) {
|
|
28
30
|
throw new Error(`Duplicated item key: ${key}`);
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// Reserve the key so a concurrent registration of the same key throws
|
|
33
|
+
state.pendingKeys.add(key);
|
|
34
|
+
try {
|
|
35
|
+
await state.hooks.willRegister.call({
|
|
36
|
+
key,
|
|
37
|
+
value: item
|
|
38
|
+
});
|
|
39
|
+
} finally{
|
|
40
|
+
state.pendingKeys.delete(key);
|
|
41
|
+
}
|
|
34
42
|
state.registry.set(key, item);
|
|
35
43
|
await state.hooks.didRegister.call({
|
|
36
44
|
key,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-factory.js","sources":["../src/provider-factory.ts"],"sourcesContent":["import { cloneDeep } from 'lodash';\nimport {\n createAsyncSeriesHook,\n createAsyncParallelHook,\n AsyncSeriesHook,\n AsyncParallelHook,\n} from './hooks';\n\nexport interface ProviderHooksMap {\n willRegister: AsyncSeriesHook;\n didRegister: AsyncParallelHook;\n willDelete: AsyncParallelHook;\n didDelete: AsyncParallelHook;\n}\n\n/**\n * Creates a new object containing various hooks used by the providers\n */\nconst createProviderHooksMap = (): ProviderHooksMap => ({\n // Register events\n willRegister: createAsyncSeriesHook(),\n didRegister: createAsyncParallelHook(),\n // Delete events\n willDelete: createAsyncParallelHook(),\n didDelete: createAsyncParallelHook(),\n});\n\nexport interface Options {\n throwOnDuplicates?: boolean;\n}\n\ntype Item = Record<string, unknown>;\n\nexport interface Provider<T = unknown> {\n hooks: ProviderHooksMap;\n register(key: string, item: T): Promise<Provider>;\n delete(key: string): Promise<Provider>;\n get(key: string): T | undefined;\n values(): T[];\n keys(): string[];\n has(key: string): boolean;\n size(): number;\n clear(): Promise<Provider<T>>;\n}\n\nexport type ProviderFactory<T> = (options?: Options) => Provider<T>;\n\n/**\n * A Provider factory\n */\nconst providerFactory = <T = Item>(options: Options = {}): Provider<T> => {\n const { throwOnDuplicates = true } = options;\n\n const state = {\n hooks: createProviderHooksMap(),\n registry: new Map<string, T>(),\n };\n\n return {\n hooks: state.hooks,\n\n async register(key: string, item: T) {\n if (throwOnDuplicates && this.has(key)) {\n throw new Error(`Duplicated item key: ${key}`);\n }\n\n await state.hooks.willRegister.call({ key, value: item });\n\n state.registry.set(key, item);\n\n await state.hooks.didRegister.call({ key, value: cloneDeep(item) });\n\n return this;\n },\n\n async delete(key: string) {\n if (this.has(key)) {\n const item = this.get(key);\n\n await state.hooks.willDelete.call({ key, value: cloneDeep(item) });\n\n state.registry.delete(key);\n\n await state.hooks.didDelete.call({ key, value: cloneDeep(item) });\n }\n\n return this;\n },\n\n get(key: string) {\n return state.registry.get(key);\n },\n\n values() {\n return Array.from(state.registry.values());\n },\n\n keys() {\n return Array.from(state.registry.keys());\n },\n\n has(key: string) {\n return state.registry.has(key);\n },\n\n size() {\n return state.registry.size;\n },\n\n async clear() {\n const keys = this.keys();\n\n for (const key of keys) {\n await this.delete(key);\n }\n\n return this;\n },\n };\n};\n\nexport default providerFactory;\n"],"names":["createProviderHooksMap","willRegister","createAsyncSeriesHook","didRegister","createAsyncParallelHook","willDelete","didDelete","providerFactory","options","throwOnDuplicates","state","hooks","registry","Map","register","key","item","has","Error","call","value","
|
|
1
|
+
{"version":3,"file":"provider-factory.js","sources":["../src/provider-factory.ts"],"sourcesContent":["import { cloneDeep } from 'lodash';\nimport {\n createAsyncSeriesHook,\n createAsyncParallelHook,\n AsyncSeriesHook,\n AsyncParallelHook,\n} from './hooks';\n\nexport interface ProviderHooksMap {\n willRegister: AsyncSeriesHook;\n didRegister: AsyncParallelHook;\n willDelete: AsyncParallelHook;\n didDelete: AsyncParallelHook;\n}\n\n/**\n * Creates a new object containing various hooks used by the providers\n */\nconst createProviderHooksMap = (): ProviderHooksMap => ({\n // Register events\n willRegister: createAsyncSeriesHook(),\n didRegister: createAsyncParallelHook(),\n // Delete events\n willDelete: createAsyncParallelHook(),\n didDelete: createAsyncParallelHook(),\n});\n\nexport interface Options {\n throwOnDuplicates?: boolean;\n}\n\ntype Item = Record<string, unknown>;\n\nexport interface Provider<T = unknown> {\n hooks: ProviderHooksMap;\n register(key: string, item: T): Promise<Provider>;\n delete(key: string): Promise<Provider>;\n get(key: string): T | undefined;\n values(): T[];\n keys(): string[];\n has(key: string): boolean;\n size(): number;\n clear(): Promise<Provider<T>>;\n}\n\nexport type ProviderFactory<T> = (options?: Options) => Provider<T>;\n\n/**\n * A Provider factory\n */\nconst providerFactory = <T = Item>(options: Options = {}): Provider<T> => {\n const { throwOnDuplicates = true } = options;\n\n const state = {\n hooks: createProviderHooksMap(),\n registry: new Map<string, T>(),\n // Keys whose registration is awaiting the willRegister hook\n pendingKeys: new Set<string>(),\n };\n\n return {\n hooks: state.hooks,\n\n async register(key: string, item: T) {\n if (throwOnDuplicates && (this.has(key) || state.pendingKeys.has(key))) {\n throw new Error(`Duplicated item key: ${key}`);\n }\n\n // Reserve the key so a concurrent registration of the same key throws\n state.pendingKeys.add(key);\n\n try {\n await state.hooks.willRegister.call({ key, value: item });\n } finally {\n state.pendingKeys.delete(key);\n }\n\n state.registry.set(key, item);\n\n await state.hooks.didRegister.call({ key, value: cloneDeep(item) });\n\n return this;\n },\n\n async delete(key: string) {\n if (this.has(key)) {\n const item = this.get(key);\n\n await state.hooks.willDelete.call({ key, value: cloneDeep(item) });\n\n state.registry.delete(key);\n\n await state.hooks.didDelete.call({ key, value: cloneDeep(item) });\n }\n\n return this;\n },\n\n get(key: string) {\n return state.registry.get(key);\n },\n\n values() {\n return Array.from(state.registry.values());\n },\n\n keys() {\n return Array.from(state.registry.keys());\n },\n\n has(key: string) {\n return state.registry.has(key);\n },\n\n size() {\n return state.registry.size;\n },\n\n async clear() {\n const keys = this.keys();\n\n for (const key of keys) {\n await this.delete(key);\n }\n\n return this;\n },\n };\n};\n\nexport default providerFactory;\n"],"names":["createProviderHooksMap","willRegister","createAsyncSeriesHook","didRegister","createAsyncParallelHook","willDelete","didDelete","providerFactory","options","throwOnDuplicates","state","hooks","registry","Map","pendingKeys","Set","register","key","item","has","Error","add","call","value","delete","set","cloneDeep","get","values","Array","from","keys","size","clear"],"mappings":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AA;AAEAZ,QAAAA,GAAAA,CAAAA,CAAIF,GAAW,EAAA;AACb,YAAA,OAAOP,KAAAA,CAAME,QAAQ,CAACO,GAAG,CAACF,GAAAA,CAAAA;AAC5B,QAAA,CAAA;AAEAe,QAAAA,IAAAA,CAAAA,GAAAA;YACE,OAAOtB,KAAAA,CAAME,QAAQ,CAACoB,IAAI;AAC5B,QAAA,CAAA;QAEA,MAAMC,KAAAA,CAAAA,GAAAA;YACJ,MAAMF,IAAAA,GAAO,IAAI,CAACA,IAAI,EAAA;YAEtB,KAAK,MAAMd,OAAOc,IAAAA,CAAM;gBACtB,MAAM,IAAI,CAACP,MAAM,CAACP,GAAAA,CAAAA;AACpB,YAAA;AAEA,YAAA,OAAO,IAAI;AACb,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -17,18 +17,26 @@ import { createAsyncParallelHook, createAsyncSeriesHook } from './hooks.mjs';
|
|
|
17
17
|
const { throwOnDuplicates = true } = options;
|
|
18
18
|
const state = {
|
|
19
19
|
hooks: createProviderHooksMap(),
|
|
20
|
-
registry: new Map()
|
|
20
|
+
registry: new Map(),
|
|
21
|
+
// Keys whose registration is awaiting the willRegister hook
|
|
22
|
+
pendingKeys: new Set()
|
|
21
23
|
};
|
|
22
24
|
return {
|
|
23
25
|
hooks: state.hooks,
|
|
24
26
|
async register (key, item) {
|
|
25
|
-
if (throwOnDuplicates && this.has(key)) {
|
|
27
|
+
if (throwOnDuplicates && (this.has(key) || state.pendingKeys.has(key))) {
|
|
26
28
|
throw new Error(`Duplicated item key: ${key}`);
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
// Reserve the key so a concurrent registration of the same key throws
|
|
31
|
+
state.pendingKeys.add(key);
|
|
32
|
+
try {
|
|
33
|
+
await state.hooks.willRegister.call({
|
|
34
|
+
key,
|
|
35
|
+
value: item
|
|
36
|
+
});
|
|
37
|
+
} finally{
|
|
38
|
+
state.pendingKeys.delete(key);
|
|
39
|
+
}
|
|
32
40
|
state.registry.set(key, item);
|
|
33
41
|
await state.hooks.didRegister.call({
|
|
34
42
|
key,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-factory.mjs","sources":["../src/provider-factory.ts"],"sourcesContent":["import { cloneDeep } from 'lodash';\nimport {\n createAsyncSeriesHook,\n createAsyncParallelHook,\n AsyncSeriesHook,\n AsyncParallelHook,\n} from './hooks';\n\nexport interface ProviderHooksMap {\n willRegister: AsyncSeriesHook;\n didRegister: AsyncParallelHook;\n willDelete: AsyncParallelHook;\n didDelete: AsyncParallelHook;\n}\n\n/**\n * Creates a new object containing various hooks used by the providers\n */\nconst createProviderHooksMap = (): ProviderHooksMap => ({\n // Register events\n willRegister: createAsyncSeriesHook(),\n didRegister: createAsyncParallelHook(),\n // Delete events\n willDelete: createAsyncParallelHook(),\n didDelete: createAsyncParallelHook(),\n});\n\nexport interface Options {\n throwOnDuplicates?: boolean;\n}\n\ntype Item = Record<string, unknown>;\n\nexport interface Provider<T = unknown> {\n hooks: ProviderHooksMap;\n register(key: string, item: T): Promise<Provider>;\n delete(key: string): Promise<Provider>;\n get(key: string): T | undefined;\n values(): T[];\n keys(): string[];\n has(key: string): boolean;\n size(): number;\n clear(): Promise<Provider<T>>;\n}\n\nexport type ProviderFactory<T> = (options?: Options) => Provider<T>;\n\n/**\n * A Provider factory\n */\nconst providerFactory = <T = Item>(options: Options = {}): Provider<T> => {\n const { throwOnDuplicates = true } = options;\n\n const state = {\n hooks: createProviderHooksMap(),\n registry: new Map<string, T>(),\n };\n\n return {\n hooks: state.hooks,\n\n async register(key: string, item: T) {\n if (throwOnDuplicates && this.has(key)) {\n throw new Error(`Duplicated item key: ${key}`);\n }\n\n await state.hooks.willRegister.call({ key, value: item });\n\n state.registry.set(key, item);\n\n await state.hooks.didRegister.call({ key, value: cloneDeep(item) });\n\n return this;\n },\n\n async delete(key: string) {\n if (this.has(key)) {\n const item = this.get(key);\n\n await state.hooks.willDelete.call({ key, value: cloneDeep(item) });\n\n state.registry.delete(key);\n\n await state.hooks.didDelete.call({ key, value: cloneDeep(item) });\n }\n\n return this;\n },\n\n get(key: string) {\n return state.registry.get(key);\n },\n\n values() {\n return Array.from(state.registry.values());\n },\n\n keys() {\n return Array.from(state.registry.keys());\n },\n\n has(key: string) {\n return state.registry.has(key);\n },\n\n size() {\n return state.registry.size;\n },\n\n async clear() {\n const keys = this.keys();\n\n for (const key of keys) {\n await this.delete(key);\n }\n\n return this;\n },\n };\n};\n\nexport default providerFactory;\n"],"names":["createProviderHooksMap","willRegister","createAsyncSeriesHook","didRegister","createAsyncParallelHook","willDelete","didDelete","providerFactory","options","throwOnDuplicates","state","hooks","registry","Map","register","key","item","has","Error","call","value","
|
|
1
|
+
{"version":3,"file":"provider-factory.mjs","sources":["../src/provider-factory.ts"],"sourcesContent":["import { cloneDeep } from 'lodash';\nimport {\n createAsyncSeriesHook,\n createAsyncParallelHook,\n AsyncSeriesHook,\n AsyncParallelHook,\n} from './hooks';\n\nexport interface ProviderHooksMap {\n willRegister: AsyncSeriesHook;\n didRegister: AsyncParallelHook;\n willDelete: AsyncParallelHook;\n didDelete: AsyncParallelHook;\n}\n\n/**\n * Creates a new object containing various hooks used by the providers\n */\nconst createProviderHooksMap = (): ProviderHooksMap => ({\n // Register events\n willRegister: createAsyncSeriesHook(),\n didRegister: createAsyncParallelHook(),\n // Delete events\n willDelete: createAsyncParallelHook(),\n didDelete: createAsyncParallelHook(),\n});\n\nexport interface Options {\n throwOnDuplicates?: boolean;\n}\n\ntype Item = Record<string, unknown>;\n\nexport interface Provider<T = unknown> {\n hooks: ProviderHooksMap;\n register(key: string, item: T): Promise<Provider>;\n delete(key: string): Promise<Provider>;\n get(key: string): T | undefined;\n values(): T[];\n keys(): string[];\n has(key: string): boolean;\n size(): number;\n clear(): Promise<Provider<T>>;\n}\n\nexport type ProviderFactory<T> = (options?: Options) => Provider<T>;\n\n/**\n * A Provider factory\n */\nconst providerFactory = <T = Item>(options: Options = {}): Provider<T> => {\n const { throwOnDuplicates = true } = options;\n\n const state = {\n hooks: createProviderHooksMap(),\n registry: new Map<string, T>(),\n // Keys whose registration is awaiting the willRegister hook\n pendingKeys: new Set<string>(),\n };\n\n return {\n hooks: state.hooks,\n\n async register(key: string, item: T) {\n if (throwOnDuplicates && (this.has(key) || state.pendingKeys.has(key))) {\n throw new Error(`Duplicated item key: ${key}`);\n }\n\n // Reserve the key so a concurrent registration of the same key throws\n state.pendingKeys.add(key);\n\n try {\n await state.hooks.willRegister.call({ key, value: item });\n } finally {\n state.pendingKeys.delete(key);\n }\n\n state.registry.set(key, item);\n\n await state.hooks.didRegister.call({ key, value: cloneDeep(item) });\n\n return this;\n },\n\n async delete(key: string) {\n if (this.has(key)) {\n const item = this.get(key);\n\n await state.hooks.willDelete.call({ key, value: cloneDeep(item) });\n\n state.registry.delete(key);\n\n await state.hooks.didDelete.call({ key, value: cloneDeep(item) });\n }\n\n return this;\n },\n\n get(key: string) {\n return state.registry.get(key);\n },\n\n values() {\n return Array.from(state.registry.values());\n },\n\n keys() {\n return Array.from(state.registry.keys());\n },\n\n has(key: string) {\n return state.registry.has(key);\n },\n\n size() {\n return state.registry.size;\n },\n\n async clear() {\n const keys = this.keys();\n\n for (const key of keys) {\n await this.delete(key);\n }\n\n return this;\n },\n };\n};\n\nexport default providerFactory;\n"],"names":["createProviderHooksMap","willRegister","createAsyncSeriesHook","didRegister","createAsyncParallelHook","willDelete","didDelete","providerFactory","options","throwOnDuplicates","state","hooks","registry","Map","pendingKeys","Set","register","key","item","has","Error","add","call","value","delete","set","cloneDeep","get","values","Array","from","keys","size","clear"],"mappings":";;;AAeA;;IAGA,MAAMA,sBAAAA,GAAyB,KAAyB;;QAEtDC,YAAAA,EAAcC,qBAAAA,EAAAA;QACdC,WAAAA,EAAaC,uBAAAA,EAAAA;;QAEbC,UAAAA,EAAYD,uBAAAA,EAAAA;QACZE,SAAAA,EAAWF,uBAAAA;KACb,CAAA;AAsBA;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,CAACoB,IAAI;AAC5B,QAAA,CAAA;QAEA,MAAMC,KAAAA,CAAAA,GAAAA;YACJ,MAAMF,IAAAA,GAAO,IAAI,CAACA,IAAI,EAAA;YAEtB,KAAK,MAAMd,OAAOc,IAAAA,CAAM;gBACtB,MAAM,IAAI,CAACP,MAAM,CAACP,GAAAA,CAAAA;AACpB,YAAA;AAEA,YAAA,OAAO,IAAI;AACb,QAAA;AACF,KAAA;AACF;;;;"}
|
package/dist/sort-query.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _ from 'lodash';
|
|
2
2
|
|
|
3
|
-
const isPlainObject = (value)=>
|
|
3
|
+
const isPlainObject = (value)=>_.isPlainObject(value);
|
|
4
4
|
/**
|
|
5
5
|
* Splits a REST sort string into trimmed segments with a non-empty field (drops '', ',', trailing commas).
|
|
6
6
|
*/ function getMeaningfulSortSegments(sort) {
|
package/dist/sort-query.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort-query.mjs","sources":["../src/sort-query.ts"],"sourcesContent":["import _ from 'lodash';\n\nexport type SortOrder = 'asc' | 'desc';\n\nexport interface SortParamsObject {\n [key: string]: SortOrder | SortParamsObject;\n}\n\nexport type SortParams = string | string[] | SortParamsObject | SortParamsObject[];\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => _.isPlainObject(value);\n\n/**\n * Splits a REST sort string into trimmed segments with a non-empty field (drops '', ',', trailing commas).\n */\nexport function getMeaningfulSortSegments(sort: string): string[] {\n return sort\n .split(',')\n .map((segment) => segment.trim())\n .filter((segment) => {\n if (segment.length === 0) {\n return false;\n }\n\n const [field] = segment.split(':');\n return field.trim().length > 0;\n });\n}\n\n/**\n * Whether a nested sort object ({ field: 'asc' } or { relation: { name: 'desc' } }) specifies\n * at least one field to sort on. Empty objects and keys with blank orders are treated as no sort.\n */\nfunction hasMeaningfulSortObject(sort: SortParamsObject): boolean {\n return Object.keys(sort).some((key) => {\n const order = sort[key];\n\n if (typeof order === 'string') {\n return order.length > 0;\n }\n\n if (isPlainObject(order)) {\n return hasMeaningfulSortObject(order as SortParamsObject);\n }\n\n return false;\n });\n}\n\n/** Whether a REST-style sort string contains at least one meaningful segment. */\nfunction hasMeaningfulStringSort(sort: string): boolean {\n return getMeaningfulSortSegments(sort).length > 0;\n}\n\n/**\n * Whether `sort` carries a real ordering instruction. Empty or absent sort must stay undefined so\n * populated relations keep join-table connect order (GraphQL defaults nested sort to []; REST qs\n * `sort[]` with strictNullHandling parses to `[null]`).\n */\nexport function hasSort(sort?: unknown): sort is SortParams {\n if (sort === undefined || sort === null) {\n return false;\n }\n\n if (typeof sort === 'string') {\n return hasMeaningfulStringSort(sort);\n }\n\n if (Array.isArray(sort)) {\n if (sort.length === 0) {\n return false;\n }\n\n return sort.some((item) => {\n if (typeof item === 'string') {\n return hasMeaningfulStringSort(item);\n }\n\n if (isPlainObject(item)) {\n return hasMeaningfulSortObject(item as SortParamsObject);\n }\n\n return false;\n });\n }\n\n if (isPlainObject(sort)) {\n return hasMeaningfulSortObject(sort as SortParamsObject);\n }\n\n return false;\n}\n"],"names":["isPlainObject","value","_","getMeaningfulSortSegments","sort","split","map","segment","trim","filter","length","field","hasMeaningfulSortObject","Object","keys","some","key","order","hasMeaningfulStringSort","hasSort","undefined","Array","isArray","item"],"mappings":";;AAUA,MAAMA,aAAAA,GAAgB,CAACC,KAAAA,GAAqDC,
|
|
1
|
+
{"version":3,"file":"sort-query.mjs","sources":["../src/sort-query.ts"],"sourcesContent":["import _ from 'lodash';\n\nexport type SortOrder = 'asc' | 'desc';\n\nexport interface SortParamsObject {\n [key: string]: SortOrder | SortParamsObject;\n}\n\nexport type SortParams = string | string[] | SortParamsObject | SortParamsObject[];\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => _.isPlainObject(value);\n\n/**\n * Splits a REST sort string into trimmed segments with a non-empty field (drops '', ',', trailing commas).\n */\nexport function getMeaningfulSortSegments(sort: string): string[] {\n return sort\n .split(',')\n .map((segment) => segment.trim())\n .filter((segment) => {\n if (segment.length === 0) {\n return false;\n }\n\n const [field] = segment.split(':');\n return field.trim().length > 0;\n });\n}\n\n/**\n * Whether a nested sort object ({ field: 'asc' } or { relation: { name: 'desc' } }) specifies\n * at least one field to sort on. Empty objects and keys with blank orders are treated as no sort.\n */\nfunction hasMeaningfulSortObject(sort: SortParamsObject): boolean {\n return Object.keys(sort).some((key) => {\n const order = sort[key];\n\n if (typeof order === 'string') {\n return order.length > 0;\n }\n\n if (isPlainObject(order)) {\n return hasMeaningfulSortObject(order as SortParamsObject);\n }\n\n return false;\n });\n}\n\n/** Whether a REST-style sort string contains at least one meaningful segment. */\nfunction hasMeaningfulStringSort(sort: string): boolean {\n return getMeaningfulSortSegments(sort).length > 0;\n}\n\n/**\n * Whether `sort` carries a real ordering instruction. Empty or absent sort must stay undefined so\n * populated relations keep join-table connect order (GraphQL defaults nested sort to []; REST qs\n * `sort[]` with strictNullHandling parses to `[null]`).\n */\nexport function hasSort(sort?: unknown): sort is SortParams {\n if (sort === undefined || sort === null) {\n return false;\n }\n\n if (typeof sort === 'string') {\n return hasMeaningfulStringSort(sort);\n }\n\n if (Array.isArray(sort)) {\n if (sort.length === 0) {\n return false;\n }\n\n return sort.some((item) => {\n if (typeof item === 'string') {\n return hasMeaningfulStringSort(item);\n }\n\n if (isPlainObject(item)) {\n return hasMeaningfulSortObject(item as SortParamsObject);\n }\n\n return false;\n });\n }\n\n if (isPlainObject(sort)) {\n return hasMeaningfulSortObject(sort as SortParamsObject);\n }\n\n return false;\n}\n"],"names":["isPlainObject","value","_","getMeaningfulSortSegments","sort","split","map","segment","trim","filter","length","field","hasMeaningfulSortObject","Object","keys","some","key","order","hasMeaningfulStringSort","hasSort","undefined","Array","isArray","item"],"mappings":";;AAUA,MAAMA,aAAAA,GAAgB,CAACC,KAAAA,GAAqDC,CAAAA,CAAEF,aAAa,CAACC,KAAAA,CAAAA;AAE5F;;IAGO,SAASE,yBA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BAAAA,CAAwBd,IAAAA,CAAAA;AACjC,IAAA;IAEA,IAAIiB,KAAAA,CAAMC,OAAO,CAAClB,IAAAA,CAAAA,EAAO;QACvB,IAAIA,IAAAA,CAAKM,MAAM,KAAK,CAAA,EAAG;YACrB,OAAO,KAAA;AACT,QAAA;QAEA,OAAON,IAAAA,CAAKW,IAAI,CAAC,CAACQ,IAAAA,GAAAA;YAChB,IAAI,OAAOA,SAAS,QAAA,EAAU;AAC5B,gBAAA,OAAOL,uBAAAA,CAAwBK,IAAAA,CAAAA;AACjC,YAAA;AAEA,YAAA,IAAIvB,cAAcuB,IAAAA,CAAAA,EAAO;AACvB,gBAAA,OAAOX,uBAAAA,CAAwBW,IAAAA,CAAAA;AACjC,YAAA;YAEA,OAAO,KAAA;AACT,QAAA,CAAA,CAAA;AACF,IAAA;AAEA,IAAA,IAAIvB,cAAcI,IAAAA,CAAAA,EAAO;AACvB,QAAA,OAAOQ,uBAAAA,CAAwBR,IAAAA,CAAAA;AACjC,IAAA;IAEA,OAAO,KAAA;AACT;;;;"}
|
package/dist/yup.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as yup from 'yup';
|
|
2
2
|
export * from 'yup';
|
|
3
|
-
import
|
|
3
|
+
import _, { get, isNumber } from 'lodash';
|
|
4
4
|
import { isCamelCase, isKebabCase } from './primitives/strings.mjs';
|
|
5
5
|
import { printValue } from './print-value.mjs';
|
|
6
6
|
|
|
7
7
|
const strapiID = ()=>new StrapiIDSchema();
|
|
8
|
-
const isNotNilTest = (value)=>!
|
|
9
|
-
const isNotNullTest = (value)=>!
|
|
8
|
+
const isNotNilTest = (value)=>!_.isNil(value);
|
|
9
|
+
const isNotNullTest = (value)=>!_.isNull(value);
|
|
10
10
|
yup.addMethod(yup.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {
|
|
11
11
|
return this.test('defined', msg, isNotNilTest);
|
|
12
12
|
});
|
|
@@ -14,7 +14,7 @@ yup.addMethod(yup.mixed, 'notNull', function isNotNull(msg = '${path} cannot be
|
|
|
14
14
|
return this.test('defined', msg, isNotNullTest);
|
|
15
15
|
});
|
|
16
16
|
yup.addMethod(yup.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {
|
|
17
|
-
return this.test('is a function', message, (value)=>
|
|
17
|
+
return this.test('is a function', message, (value)=>_.isUndefined(value) || _.isFunction(value));
|
|
18
18
|
});
|
|
19
19
|
yup.addMethod(yup.string, 'isCamelCase', function isCamelCase$1(message = '${path} is not in camel case (anExampleOfCamelCase)') {
|
|
20
20
|
return this.test('is in camelCase', message, (value)=>value ? isCamelCase(value) : true);
|
|
@@ -23,7 +23,7 @@ yup.addMethod(yup.string, 'isKebabCase', function isKebabCase$1(message = '${pat
|
|
|
23
23
|
return this.test('is in kebab-case', message, (value)=>value ? isKebabCase(value) : true);
|
|
24
24
|
});
|
|
25
25
|
yup.addMethod(yup.object, 'onlyContainsFunctions', function onlyContainsFunctions(message = '${path} contains values that are not functions') {
|
|
26
|
-
return this.test('only contains functions', message, (value)=>
|
|
26
|
+
return this.test('only contains functions', message, (value)=>_.isUndefined(value) || value && Object.values(value).every(_.isFunction));
|
|
27
27
|
});
|
|
28
28
|
yup.addMethod(yup.array, 'uniqueProperty', function uniqueProperty(propertyName, message) {
|
|
29
29
|
return this.test('unique', message, function unique(list) {
|
package/dist/yup.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yup.mjs","sources":["../src/yup.ts"],"sourcesContent":["/* eslint-disable no-template-curly-in-string */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport * as yup from 'yup';\nimport _, { isNumber, get } from 'lodash';\nimport { strings } from './primitives';\nimport { printValue } from './print-value';\n\nexport * from 'yup';\n\nexport const strapiID = (): InstanceType<typeof StrapiIDSchema> => new StrapiIDSchema();\n\nconst isNotNilTest = (value: unknown) => !_.isNil(value);\n\nconst isNotNullTest = (value: unknown) => !_.isNull(value);\n\nyup.addMethod(yup.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {\n return this.test('defined', msg, isNotNilTest);\n});\n\nyup.addMethod(yup.mixed, 'notNull', function isNotNull(msg = '${path} cannot be null.') {\n return this.test('defined', msg, isNotNullTest);\n});\n\nyup.addMethod(yup.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {\n return this.test(\n 'is a function',\n message,\n (value) => _.isUndefined(value) || _.isFunction(value)\n );\n});\n\nyup.addMethod(\n yup.string,\n 'isCamelCase',\n function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {\n return this.test('is in camelCase', message, (value) =>\n value ? strings.isCamelCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.string,\n 'isKebabCase',\n function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {\n return this.test('is in kebab-case', message, (value) =>\n value ? strings.isKebabCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.object,\n 'onlyContainsFunctions',\n function onlyContainsFunctions(message = '${path} contains values that are not functions') {\n return this.test(\n 'only contains functions',\n message,\n (value) => _.isUndefined(value) || (value && Object.values(value).every(_.isFunction))\n );\n }\n);\n\nyup.addMethod(\n yup.array,\n 'uniqueProperty',\n function uniqueProperty(propertyName: string, message: string) {\n return this.test('unique', message, function unique(list) {\n const errors: yup.ValidationError[] = [];\n\n list?.forEach((element, index) => {\n const sameElements = list.filter(\n (e) => get(e, propertyName) === get(element, propertyName)\n );\n if (sameElements.length > 1) {\n errors.push(\n this.createError({\n path: `${this.path}[${index}].${propertyName}`,\n message,\n })\n );\n }\n });\n\n if (errors.length) {\n throw new yup.ValidationError(errors);\n }\n return true;\n });\n }\n);\n\nexport class StrapiIDSchema extends yup.MixedSchema {\n constructor() {\n super({ type: 'strapiID' });\n }\n\n _typeCheck(value: unknown): value is string | number {\n return typeof value === 'string' || (isNumber(value) && Number.isInteger(value) && value >= 0);\n }\n}\n\ndeclare module 'yup' {\n // const strapiID: () => InstanceType<typeof StrapiIDSchema>;\n\n export interface BaseSchema {\n isFunction(message?: string): this;\n notNil(message?: string): this;\n notNull(message?: string): this;\n }\n\n export interface StringSchema {\n isCamelCase(message?: string): this;\n isKebabCase(message?: string): this;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n export interface ObjectSchema<TShape> {\n onlyContainsFunctions(message?: string): this;\n }\n}\n\ninterface NoTypeOptions {\n path: string;\n type: string;\n value: unknown;\n originalValue: unknown;\n}\n\n// Temporary fix of this issue : https://github.com/jquense/yup/issues/616\nyup.setLocale({\n mixed: {\n notType(options: NoTypeOptions) {\n const { path, type, value, originalValue } = options;\n const isCast = originalValue != null && originalValue !== value;\n const msg =\n `${path} must be a \\`${type}\\` type, ` +\n `but the final value was: \\`${printValue(value, true)}\\`${\n isCast ? ` (cast from the value \\`${printValue(originalValue, true)}\\`).` : '.'\n }`;\n\n /* Remove comment that is not supposed to be seen by the enduser\n if (value === null) {\n msg += `\\n If \"null\" is intended as an empty value be sure to mark the schema as \\`.nullable()\\``;\n }\n */\n return msg;\n },\n },\n});\n"],"names":["strapiID","StrapiIDSchema","isNotNilTest","value","_","isNil","isNotNullTest","isNull","yup","addMethod","mixed","isNotNill","msg","test","isNotNull","isFunction","message","isUndefined","string","isCamelCase","strings","isKebabCase","object","onlyContainsFunctions","Object","values","every","array","uniqueProperty","propertyName","unique","list","errors","forEach","element","index","sameElements","filter","e","get","length","push","createError","path","ValidationError","MixedSchema","_typeCheck","isNumber","Number","isInteger","type","setLocale","notType","options","originalValue","isCast","printValue"],"mappings":";;;;;;AASO,MAAMA,QAAAA,GAAW,IAA2C,IAAIC,cAAAA;AAEvE,MAAMC,eAAe,CAACC,KAAAA,GAAmB,CAACC,
|
|
1
|
+
{"version":3,"file":"yup.mjs","sources":["../src/yup.ts"],"sourcesContent":["/* eslint-disable no-template-curly-in-string */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport * as yup from 'yup';\nimport _, { isNumber, get } from 'lodash';\nimport { strings } from './primitives';\nimport { printValue } from './print-value';\n\nexport * from 'yup';\n\nexport const strapiID = (): InstanceType<typeof StrapiIDSchema> => new StrapiIDSchema();\n\nconst isNotNilTest = (value: unknown) => !_.isNil(value);\n\nconst isNotNullTest = (value: unknown) => !_.isNull(value);\n\nyup.addMethod(yup.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {\n return this.test('defined', msg, isNotNilTest);\n});\n\nyup.addMethod(yup.mixed, 'notNull', function isNotNull(msg = '${path} cannot be null.') {\n return this.test('defined', msg, isNotNullTest);\n});\n\nyup.addMethod(yup.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {\n return this.test(\n 'is a function',\n message,\n (value) => _.isUndefined(value) || _.isFunction(value)\n );\n});\n\nyup.addMethod(\n yup.string,\n 'isCamelCase',\n function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {\n return this.test('is in camelCase', message, (value) =>\n value ? strings.isCamelCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.string,\n 'isKebabCase',\n function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {\n return this.test('is in kebab-case', message, (value) =>\n value ? strings.isKebabCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.object,\n 'onlyContainsFunctions',\n function onlyContainsFunctions(message = '${path} contains values that are not functions') {\n return this.test(\n 'only contains functions',\n message,\n (value) => _.isUndefined(value) || (value && Object.values(value).every(_.isFunction))\n );\n }\n);\n\nyup.addMethod(\n yup.array,\n 'uniqueProperty',\n function uniqueProperty(propertyName: string, message: string) {\n return this.test('unique', message, function unique(list) {\n const errors: yup.ValidationError[] = [];\n\n list?.forEach((element, index) => {\n const sameElements = list.filter(\n (e) => get(e, propertyName) === get(element, propertyName)\n );\n if (sameElements.length > 1) {\n errors.push(\n this.createError({\n path: `${this.path}[${index}].${propertyName}`,\n message,\n })\n );\n }\n });\n\n if (errors.length) {\n throw new yup.ValidationError(errors);\n }\n return true;\n });\n }\n);\n\nexport class StrapiIDSchema extends yup.MixedSchema {\n constructor() {\n super({ type: 'strapiID' });\n }\n\n _typeCheck(value: unknown): value is string | number {\n return typeof value === 'string' || (isNumber(value) && Number.isInteger(value) && value >= 0);\n }\n}\n\ndeclare module 'yup' {\n // const strapiID: () => InstanceType<typeof StrapiIDSchema>;\n\n export interface BaseSchema {\n isFunction(message?: string): this;\n notNil(message?: string): this;\n notNull(message?: string): this;\n }\n\n export interface StringSchema {\n isCamelCase(message?: string): this;\n isKebabCase(message?: string): this;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n export interface ObjectSchema<TShape> {\n onlyContainsFunctions(message?: string): this;\n }\n}\n\ninterface NoTypeOptions {\n path: string;\n type: string;\n value: unknown;\n originalValue: unknown;\n}\n\n// Temporary fix of this issue : https://github.com/jquense/yup/issues/616\nyup.setLocale({\n mixed: {\n notType(options: NoTypeOptions) {\n const { path, type, value, originalValue } = options;\n const isCast = originalValue != null && originalValue !== value;\n const msg =\n `${path} must be a \\`${type}\\` type, ` +\n `but the final value was: \\`${printValue(value, true)}\\`${\n isCast ? ` (cast from the value \\`${printValue(originalValue, true)}\\`).` : '.'\n }`;\n\n /* Remove comment that is not supposed to be seen by the enduser\n if (value === null) {\n msg += `\\n If \"null\" is intended as an empty value be sure to mark the schema as \\`.nullable()\\``;\n }\n */\n return msg;\n },\n },\n});\n"],"names":["strapiID","StrapiIDSchema","isNotNilTest","value","_","isNil","isNotNullTest","isNull","yup","addMethod","mixed","isNotNill","msg","test","isNotNull","isFunction","message","isUndefined","string","isCamelCase","strings","isKebabCase","object","onlyContainsFunctions","Object","values","every","array","uniqueProperty","propertyName","unique","list","errors","forEach","element","index","sameElements","filter","e","get","length","push","createError","path","ValidationError","MixedSchema","_typeCheck","isNumber","Number","isInteger","type","setLocale","notType","options","originalValue","isCast","printValue"],"mappings":";;;;;;AASO,MAAMA,QAAAA,GAAW,IAA2C,IAAIC,cAAAA;AAEvE,MAAMC,eAAe,CAACC,KAAAA,GAAmB,CAACC,CAAAA,CAAEC,KAAK,CAACF,KAAAA,CAAAA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ACF;AACF,CAAA,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.61.0",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
"@types/http-errors": "2.0.4",
|
|
65
65
|
"@types/jest": "29.5.2",
|
|
66
66
|
"@types/koa": "2.15.2",
|
|
67
|
-
"@types/node": "20.
|
|
68
|
-
"eslint-config-custom": "5.
|
|
67
|
+
"@types/node": "22.20.0",
|
|
68
|
+
"eslint-config-custom": "5.61.0",
|
|
69
69
|
"jest": "29.6.0",
|
|
70
70
|
"koa": "2.16.4",
|
|
71
71
|
"koa-body": "6.0.1",
|
|
72
|
-
"tsconfig": "5.
|
|
72
|
+
"tsconfig": "5.61.0",
|
|
73
73
|
"vitest": "catalog:",
|
|
74
|
-
"vitest-config": "5.
|
|
74
|
+
"vitest-config": "5.61.0"
|
|
75
75
|
},
|
|
76
76
|
"engines": {
|
|
77
|
-
"node": ">=
|
|
77
|
+
"node": ">=22.0.0 <=26.x.x",
|
|
78
78
|
"npm": ">=6.0.0"
|
|
79
79
|
}
|
|
80
80
|
}
|