@payloadcms/graphql 4.0.0-internal.43ccea7 → 4.0.0-internal.44ac9c8
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/packages/graphql-query-complexity/QueryComplexity.d.ts.map +1 -1
- package/dist/packages/graphql-query-complexity/estimators/simple/index.d.ts.map +1 -1
- package/dist/resolvers/collections/find.js +1 -1
- package/dist/resolvers/collections/find.js.map +1 -1
- package/dist/resolvers/collections/findByID.js +1 -1
- package/dist/resolvers/collections/findByID.js.map +1 -1
- package/dist/resolvers/collections/findVersionByID.js +1 -1
- package/dist/resolvers/collections/findVersionByID.js.map +1 -1
- package/dist/resolvers/collections/findVersions.js +1 -1
- package/dist/resolvers/collections/findVersions.js.map +1 -1
- package/dist/resolvers/globals/findOne.js +1 -1
- package/dist/resolvers/globals/findOne.js.map +1 -1
- package/dist/resolvers/globals/findVersionByID.js +1 -1
- package/dist/resolvers/globals/findVersionByID.js.map +1 -1
- package/dist/resolvers/globals/findVersions.js +1 -1
- package/dist/resolvers/globals/findVersions.js.map +1 -1
- package/dist/schema/buildFallbackLocaleInputType.d.ts.map +1 -1
- package/dist/schema/buildLocaleInputType.d.ts.map +1 -1
- package/dist/schema/buildMutationInputType.d.ts.map +1 -1
- package/dist/schema/buildPaginatedListType.d.ts.map +1 -1
- package/dist/schema/buildPoliciesType.d.ts.map +1 -1
- package/dist/schema/buildWhereInputType.d.ts.map +1 -1
- package/dist/schema/fieldToSchemaMap.js +3 -3
- package/dist/schema/fieldToSchemaMap.js.map +1 -1
- package/dist/schema/fieldToWhereInputSchemaMap.d.ts.map +1 -1
- package/dist/schema/initCollections.d.ts.map +1 -1
- package/dist/schema/initCollections.js +9 -6
- package/dist/schema/initCollections.js.map +1 -1
- package/dist/schema/isFieldNullable.d.ts.map +1 -1
- package/dist/schema/operators.d.ts.map +1 -1
- package/dist/schema/recursivelyBuildNestedPaths.d.ts.map +1 -1
- package/dist/schema/withNullableType.d.ts.map +1 -1
- package/dist/schema/withOperators.d.ts +6 -0
- package/dist/schema/withOperators.d.ts.map +1 -1
- package/dist/schema/withOperators.js +15 -0
- package/dist/schema/withOperators.js.map +1 -1
- package/dist/utilities/combineParentName.d.ts.map +1 -1
- package/dist/utilities/formatName.d.ts.map +1 -1
- package/dist/utilities/formatOptions.d.ts.map +1 -1
- package/dist/utilities/formatUtcOffset.d.ts.map +1 -1
- package/dist/utilities/groupOrTabHasRequiredSubfield.d.ts.map +1 -1
- package/dist/utilities/select.d.ts +4 -3
- package/dist/utilities/select.d.ts.map +1 -1
- package/dist/utilities/select.js +83 -45
- package/dist/utilities/select.js.map +1 -1
- package/package.json +3 -3
- package/dist/utilities/formatName.spec.js +0 -57
- package/dist/utilities/formatName.spec.js.map +0 -1
- package/dist/utilities/formatUtcOffset.spec.js +0 -142
- package/dist/utilities/formatUtcOffset.spec.js.map +0 -1
|
@@ -249,6 +249,12 @@ const gqlTypeCache = {};
|
|
|
249
249
|
* @param field the field for which their valid operators inside a "where" argument is being defined
|
|
250
250
|
* @param parentName the name of the parent field (if any)
|
|
251
251
|
* @returns all the operators (including their types) which can be used as a condition for a given field inside a where
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* A has-many relationship accepts a nested query with its relationship operators:
|
|
255
|
+
* ```graphql
|
|
256
|
+
* Burgers(where: { ingredients: { not_equals: { isHealthy: { equals: false } } } })
|
|
257
|
+
* ```
|
|
252
258
|
*/ export const withOperators = (field, parentName)=>{
|
|
253
259
|
if (!defaults?.[field.type]) {
|
|
254
260
|
throw new Error(`Error: ${field.type} has no defaults configured.`);
|
|
@@ -258,6 +264,15 @@ const gqlTypeCache = {};
|
|
|
258
264
|
const fieldOperators = [
|
|
259
265
|
...defaults[field.type].operators
|
|
260
266
|
];
|
|
267
|
+
// These operators accept a complete `where` query for the one collection targeted by the
|
|
268
|
+
// relationship. Polymorphic relationships are excluded because they can target multiple schemas.
|
|
269
|
+
if ((field.type === 'relationship' || field.type === 'upload') && field.hasMany && typeof field.relationTo === 'string') {
|
|
270
|
+
// `equals` and `not_equals` already exist for relationship fields.
|
|
271
|
+
fieldOperators.push({
|
|
272
|
+
name: 'contains',
|
|
273
|
+
type: GraphQLJSON
|
|
274
|
+
});
|
|
275
|
+
}
|
|
261
276
|
if (!('required' in field) || !field.required) {
|
|
262
277
|
fieldOperators.push({
|
|
263
278
|
name: 'exists',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/withOperators.ts"],"sourcesContent":["import type { GraphQLType } from 'graphql'\nimport type { FieldAffectingData, NumberField, RadioField, SelectField } from 'payload'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInputObjectType,\n GraphQLInt,\n GraphQLList,\n GraphQLString,\n} from 'graphql'\nimport { DateTimeResolver, EmailAddressResolver } from 'graphql-scalars'\nimport { optionIsObject } from 'payload/shared'\n\nimport { GraphQLJSON } from '../packages/graphql-type-json/index.js'\nimport { combineParentName } from '../utilities/combineParentName.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { operators } from './operators.js'\n\ntype staticTypes =\n | 'checkbox'\n | 'code'\n | 'date'\n | 'email'\n | 'json'\n | 'number'\n | 'point'\n | 'relationship'\n | 'richText'\n | 'text'\n | 'textarea'\n | 'upload'\n\ntype dynamicTypes = 'radio' | 'select'\n\nconst GeoJSONObject = new GraphQLInputObjectType({\n name: 'GeoJSONObject',\n fields: {\n type: { type: GraphQLString },\n coordinates: {\n type: GraphQLJSON,\n },\n },\n})\n\ntype DefaultsType = {\n [key in dynamicTypes]: {\n operators: {\n name: string\n type: (field: FieldAffectingData, parentName: string) => GraphQLType\n }[]\n }\n} & {\n [key in staticTypes]: {\n operators: {\n name: string\n type: ((field: FieldAffectingData, parentName: string) => GraphQLType) | GraphQLType\n }[]\n }\n}\n\nconst defaults: DefaultsType = {\n checkbox: {\n operators: [\n ...operators.equality.map((operator) => ({\n name: operator,\n type: GraphQLBoolean,\n })),\n ],\n },\n code: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n date: {\n operators: [\n ...[...operators.equality, ...operators.comparison, 'like'].map((operator) => ({\n name: operator,\n type: DateTimeResolver,\n })),\n ],\n },\n email: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: EmailAddressResolver,\n })),\n ],\n },\n json: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.geojson].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n number: {\n operators: [\n ...[...operators.equality, ...operators.comparison].map((operator) => ({\n name: operator,\n type: (field: NumberField): GraphQLType => {\n return field?.name === 'id' ? GraphQLInt : GraphQLFloat\n },\n })),\n ],\n },\n point: {\n operators: [\n ...[...operators.equality, ...operators.comparison, ...operators.geo].map((operator) => ({\n name: operator,\n type: new GraphQLList(GraphQLFloat),\n })),\n ...operators.geojson.map((operator) => ({\n name: operator,\n /**\n * @example:\n * within: {\n * type: \"Polygon\",\n * coordinates: [[\n * [0.0, 0.0],\n * [1.0, 1.0],\n * [1.0, 0.0],\n * [0.0, 0.0],\n * ]],\n * }\n * @example\n * intersects: {\n * type: \"Point\",\n * coordinates: [ 0.5, 0.5 ]\n * }\n */\n type: GeoJSONObject,\n })),\n ],\n },\n radio: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: (field: RadioField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n relationship: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n richText: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n select: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: (field: SelectField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n text: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n textarea: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n upload: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n // array: n/a\n // group: n/a\n // row: n/a\n // collapsible: n/a\n // tabs: n/a\n}\n\nconst listOperators = ['in', 'not_in', 'all']\n\nconst gqlTypeCache: Record<string, GraphQLType> = {}\n\n/**\n * In GraphQL, you can use \"where\" as an argument to filter a collection. Example:\n * { Posts(where: { title: { equals: \"Hello\" } }) { text } }\n * This function defines the operators for a field's condition in the \"where\" argument of the collection (it thus gets called for every field).\n * For example, in the example above, it would control that\n * - \"equals\" is a valid operator for the \"title\" field\n * - the accepted type of the \"equals\" argument has to be a string.\n *\n * @param field the field for which their valid operators inside a \"where\" argument is being defined\n * @param parentName the name of the parent field (if any)\n * @returns all the operators (including their types) which can be used as a condition for a given field inside a where\n */\nexport const withOperators = (\n field: FieldAffectingData,\n parentName: string,\n): GraphQLInputObjectType => {\n if (!defaults?.[field.type]) {\n throw new Error(`Error: ${field.type} has no defaults configured.`)\n }\n\n const name = `${combineParentName(parentName, field.name)}_operator`\n\n // Get the default operators for the field type which are hard-coded above\n const fieldOperators = [...defaults[field.type].operators]\n\n if (!('required' in field) || !field.required) {\n fieldOperators.push({\n name: 'exists',\n type: fieldOperators[0].type,\n })\n }\n\n return new GraphQLInputObjectType({\n name,\n fields: fieldOperators.reduce((objectTypeFields, operator) => {\n // Get the type of the operator. It can be either static, or dynamic (=> a function)\n let gqlType: GraphQLType =\n typeof operator.type === 'function' ? operator.type(field, parentName) : operator.type\n\n // GraphQL does not allow types with duplicate names, so we use this cache to avoid that.\n // Without this, select and radio fields would have the same name, and GraphQL would throw an error\n // This usually only happens if a custom type is returned from the operator.type function\n if (typeof operator.type === 'function' && 'name' in gqlType) {\n if (gqlTypeCache[gqlType.name]) {\n gqlType = gqlTypeCache[gqlType.name]\n } else {\n gqlTypeCache[gqlType.name] = gqlType\n }\n }\n\n if (listOperators.includes(operator.name)) {\n gqlType = new GraphQLList(gqlType)\n } else if (operator.name === 'exists') {\n gqlType = GraphQLBoolean\n }\n\n return {\n ...objectTypeFields,\n [operator.name]: {\n type: gqlType,\n },\n }\n }, {}),\n })\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInputObjectType","GraphQLInt","GraphQLList","GraphQLString","DateTimeResolver","EmailAddressResolver","optionIsObject","GraphQLJSON","combineParentName","formatName","operators","GeoJSONObject","name","fields","type","coordinates","defaults","checkbox","equality","map","operator","code","partial","date","comparison","email","contains","json","geojson","number","field","point","geo","radio","parentName","values","options","reduce","option","value","relationship","richText","select","text","textarea","upload","listOperators","gqlTypeCache","withOperators","Error","fieldOperators","required","push","objectTypeFields","gqlType","includes"],"mappings":"AAGA,SACEA,cAAc,EACdC,eAAe,EACfC,YAAY,EACZC,sBAAsB,EACtBC,UAAU,EACVC,WAAW,EACXC,aAAa,QACR,UAAS;AAChB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,kBAAiB;AACxE,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,WAAW,QAAQ,yCAAwC;AACpE,SAAS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YAAY,CAACO,QAAQ1C,IAAI,CAAC,GAAG0C;gBAC/B;YACF;YAEA,IAAIR,cAAcS,QAAQ,CAACnC,SAASR,IAAI,GAAG;gBACzC0C,UAAU,IAAIpD,YAAYoD;YAC5B,OAAO,IAAIlC,SAASR,IAAI,KAAK,UAAU;gBACrC0C,UAAUzD;YACZ;YAEA,OAAO;gBACL,GAAGwD,gBAAgB;gBACnB,CAACjC,SAASR,IAAI,CAAC,EAAE;oBACfE,MAAMwC;gBACR;YACF;QACF,GAAG,CAAC;IACN;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/schema/withOperators.ts"],"sourcesContent":["import type { GraphQLType } from 'graphql'\nimport type { FieldAffectingData, NumberField, RadioField, SelectField } from 'payload'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInputObjectType,\n GraphQLInt,\n GraphQLList,\n GraphQLString,\n} from 'graphql'\nimport { DateTimeResolver, EmailAddressResolver } from 'graphql-scalars'\nimport { optionIsObject } from 'payload/shared'\n\nimport { GraphQLJSON } from '../packages/graphql-type-json/index.js'\nimport { combineParentName } from '../utilities/combineParentName.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { operators } from './operators.js'\n\ntype staticTypes =\n | 'checkbox'\n | 'code'\n | 'date'\n | 'email'\n | 'json'\n | 'number'\n | 'point'\n | 'relationship'\n | 'richText'\n | 'text'\n | 'textarea'\n | 'upload'\n\ntype dynamicTypes = 'radio' | 'select'\n\nconst GeoJSONObject = new GraphQLInputObjectType({\n name: 'GeoJSONObject',\n fields: {\n type: { type: GraphQLString },\n coordinates: {\n type: GraphQLJSON,\n },\n },\n})\n\ntype DefaultsType = {\n [key in dynamicTypes]: {\n operators: {\n name: string\n type: (field: FieldAffectingData, parentName: string) => GraphQLType\n }[]\n }\n} & {\n [key in staticTypes]: {\n operators: {\n name: string\n type: ((field: FieldAffectingData, parentName: string) => GraphQLType) | GraphQLType\n }[]\n }\n}\n\nconst defaults: DefaultsType = {\n checkbox: {\n operators: [\n ...operators.equality.map((operator) => ({\n name: operator,\n type: GraphQLBoolean,\n })),\n ],\n },\n code: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n date: {\n operators: [\n ...[...operators.equality, ...operators.comparison, 'like'].map((operator) => ({\n name: operator,\n type: DateTimeResolver,\n })),\n ],\n },\n email: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: EmailAddressResolver,\n })),\n ],\n },\n json: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.geojson].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n number: {\n operators: [\n ...[...operators.equality, ...operators.comparison].map((operator) => ({\n name: operator,\n type: (field: NumberField): GraphQLType => {\n return field?.name === 'id' ? GraphQLInt : GraphQLFloat\n },\n })),\n ],\n },\n point: {\n operators: [\n ...[...operators.equality, ...operators.comparison, ...operators.geo].map((operator) => ({\n name: operator,\n type: new GraphQLList(GraphQLFloat),\n })),\n ...operators.geojson.map((operator) => ({\n name: operator,\n /**\n * @example:\n * within: {\n * type: \"Polygon\",\n * coordinates: [[\n * [0.0, 0.0],\n * [1.0, 1.0],\n * [1.0, 0.0],\n * [0.0, 0.0],\n * ]],\n * }\n * @example\n * intersects: {\n * type: \"Point\",\n * coordinates: [ 0.5, 0.5 ]\n * }\n */\n type: GeoJSONObject,\n })),\n ],\n },\n radio: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: (field: RadioField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n relationship: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n richText: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n select: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: (field: SelectField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n text: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n textarea: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n upload: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n // array: n/a\n // group: n/a\n // row: n/a\n // collapsible: n/a\n // tabs: n/a\n}\n\nconst listOperators = ['in', 'not_in', 'all']\n\nconst gqlTypeCache: Record<string, GraphQLType> = {}\n\n/**\n * In GraphQL, you can use \"where\" as an argument to filter a collection. Example:\n * { Posts(where: { title: { equals: \"Hello\" } }) { text } }\n * This function defines the operators for a field's condition in the \"where\" argument of the collection (it thus gets called for every field).\n * For example, in the example above, it would control that\n * - \"equals\" is a valid operator for the \"title\" field\n * - the accepted type of the \"equals\" argument has to be a string.\n *\n * @param field the field for which their valid operators inside a \"where\" argument is being defined\n * @param parentName the name of the parent field (if any)\n * @returns all the operators (including their types) which can be used as a condition for a given field inside a where\n *\n * @example\n * A has-many relationship accepts a nested query with its relationship operators:\n * ```graphql\n * Burgers(where: { ingredients: { not_equals: { isHealthy: { equals: false } } } })\n * ```\n */\nexport const withOperators = (\n field: FieldAffectingData,\n parentName: string,\n): GraphQLInputObjectType => {\n if (!defaults?.[field.type]) {\n throw new Error(`Error: ${field.type} has no defaults configured.`)\n }\n\n const name = `${combineParentName(parentName, field.name)}_operator`\n\n // Get the default operators for the field type which are hard-coded above\n const fieldOperators = [...defaults[field.type].operators]\n\n // These operators accept a complete `where` query for the one collection targeted by the\n // relationship. Polymorphic relationships are excluded because they can target multiple schemas.\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n field.hasMany &&\n typeof field.relationTo === 'string'\n ) {\n // `equals` and `not_equals` already exist for relationship fields.\n fieldOperators.push({ name: 'contains', type: GraphQLJSON })\n }\n\n if (!('required' in field) || !field.required) {\n fieldOperators.push({\n name: 'exists',\n type: fieldOperators[0].type,\n })\n }\n\n return new GraphQLInputObjectType({\n name,\n fields: fieldOperators.reduce((objectTypeFields, operator) => {\n // Get the type of the operator. It can be either static, or dynamic (=> a function)\n let gqlType: GraphQLType =\n typeof operator.type === 'function' ? operator.type(field, parentName) : operator.type\n\n // GraphQL does not allow types with duplicate names, so we use this cache to avoid that.\n // Without this, select and radio fields would have the same name, and GraphQL would throw an error\n // This usually only happens if a custom type is returned from the operator.type function\n if (typeof operator.type === 'function' && 'name' in gqlType) {\n if (gqlTypeCache[gqlType.name]) {\n gqlType = gqlTypeCache[gqlType.name]\n } else {\n gqlTypeCache[gqlType.name] = gqlType\n }\n }\n\n if (listOperators.includes(operator.name)) {\n gqlType = new GraphQLList(gqlType)\n } else if (operator.name === 'exists') {\n gqlType = GraphQLBoolean\n }\n\n return {\n ...objectTypeFields,\n [operator.name]: {\n type: gqlType,\n },\n }\n }, {}),\n })\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInputObjectType","GraphQLInt","GraphQLList","GraphQLString","DateTimeResolver","EmailAddressResolver","optionIsObject","GraphQLJSON","combineParentName","formatName","operators","GeoJSONObject","name","fields","type","coordinates","defaults","checkbox","equality","map","operator","code","partial","date","comparison","email","contains","json","geojson","number","field","point","geo","radio","parentName","values","options","reduce","option","value","relationship","richText","select","text","textarea","upload","listOperators","gqlTypeCache","withOperators","Error","fieldOperators","hasMany","relationTo","push","required","objectTypeFields","gqlType","includes"],"mappings":"AAGA,SACEA,cAAc,EACdC,eAAe,EACfC,YAAY,EACZC,sBAAsB,EACtBC,UAAU,EACVC,WAAW,EACXC,aAAa,QACR,UAAS;AAChB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,kBAAiB;AACxE,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,WAAW,QAAQ,yCAAwC;AACpE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,SAAS,QAAQ,iBAAgB;AAkB1C,MAAMC,gBAAgB,IAAIX,uBAAuB;IAC/CY,MAAM;IACNC,QAAQ;QACNC,MAAM;YAAEA,MAAMX;QAAc;QAC5BY,aAAa;YACXD,MAAMP;QACR;IACF;AACF;AAkBA,MAAMS,WAAyB;IAC7BC,UAAU;QACRP,WAAW;eACNA,UAAUQ,QAAQ,CAACC,GAAG,CAAC,CAACC,WAAc,CAAA;oBACvCR,MAAMQ;oBACNN,MAAMjB;gBACR,CAAA;SACD;IACH;IACAwB,MAAM;QACJX,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUY,OAAO;aAAC,CAACH,GAAG,CAAC,CAACC,WAAc,CAAA;oBAClER,MAAMQ;oBACNN,MAAMX;gBACR,CAAA;SACD;IACH;IACAoB,MAAM;QACJb,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUc,UAAU;gBAAE;aAAO,CAACL,GAAG,CAAC,CAACC,WAAc,CAAA;oBAC7ER,MAAMQ;oBACNN,MAAMV;gBACR,CAAA;SACD;IACH;IACAqB,OAAO;QACLf,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUY,OAAO;mBAAKZ,UAAUgB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AeG,IAAI,CAAC;YAAEzC,MAAM;YAAYE,MAAMP;QAAY;IAC5D;IAEA,IAAI,CAAE,CAAA,cAAcuB,KAAI,KAAM,CAACA,MAAMwB,QAAQ,EAAE;QAC7CJ,eAAeG,IAAI,CAAC;YAClBzC,MAAM;YACNE,MAAMoC,cAAc,CAAC,EAAE,CAACpC,IAAI;QAC9B;IACF;IAEA,OAAO,IAAId,uBAAuB;QAChCY;QACAC,QAAQqC,eAAeb,MAAM,CAAC,CAACkB,kBAAkBnC;YAC/C,oFAAoF;YACpF,IAAIoC,UACF,OAAOpC,SAASN,IAAI,KAAK,aAAaM,SAASN,IAAI,CAACgB,OAAOI,cAAcd,SAASN,IAAI;YAExF,yFAAyF;YACzF,mGAAmG;YACnG,yFAAyF;YACzF,IAAI,OAAOM,SAASN,IAAI,KAAK,cAAc,UAAU0C,SAAS;gBAC5D,IAAIT,YAAY,CAACS,QAAQ5C,IAAI,CAAC,EAAE;oBAC9B4C,UAAUT,YAAY,CAACS,QAAQ5C,IAAI,CAAC;gBACtC,OAAO;oBACLmC,YAAY,CAACS,QAAQ5C,IAAI,CAAC,GAAG4C;gBAC/B;YACF;YAEA,IAAIV,cAAcW,QAAQ,CAACrC,SAASR,IAAI,GAAG;gBACzC4C,UAAU,IAAItD,YAAYsD;YAC5B,OAAO,IAAIpC,SAASR,IAAI,KAAK,UAAU;gBACrC4C,UAAU3D;YACZ;YAEA,OAAO;gBACL,GAAG0D,gBAAgB;gBACnB,CAACnC,SAASR,IAAI,CAAC,EAAE;oBACfE,MAAM0C;gBACR;YACF;QACF,GAAG,CAAC;IACN;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combineParentName.d.ts","sourceRoot":"","sources":["../../src/utilities/combineParentName.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"combineParentName.d.ts","sourceRoot":"","sources":["../../src/utilities/combineParentName.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,WAAY,MAAM,QAAQ,MAAM,KAAG,MACb,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatName.d.ts","sourceRoot":"","sources":["../../src/utilities/formatName.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"formatName.d.ts","sourceRoot":"","sources":["../../src/utilities/formatName.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,WAAY,MAAM,KAAG,MAgC3C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatOptions.d.ts","sourceRoot":"","sources":["../../src/utilities/formatOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAItD,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"formatOptions.d.ts","sourceRoot":"","sources":["../../src/utilities/formatOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAItD,eAAO,MAAM,aAAa,UAAW,UAAU,GAAG,WAAW,OAkB5D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatUtcOffset.d.ts","sourceRoot":"","sources":["../../src/utilities/formatUtcOffset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"formatUtcOffset.d.ts","sourceRoot":"","sources":["../../src/utilities/formatUtcOffset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,UAAW,MAAM,KAAG,IAAI,GAAG,MAYtD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"groupOrTabHasRequiredSubfield.d.ts","sourceRoot":"","sources":["../../src/utilities/groupOrTabHasRequiredSubfield.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAIzC,eAAO,MAAM,6BAA6B,
|
|
1
|
+
{"version":3,"file":"groupOrTabHasRequiredSubfield.d.ts","sourceRoot":"","sources":["../../src/utilities/groupOrTabHasRequiredSubfield.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAIzC,eAAO,MAAM,6BAA6B,WAAY,KAAK,GAAG,GAAG,KAAG,OAenE,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { GraphQLResolveInfo } from 'graphql';
|
|
2
2
|
import type { TypedCollectionSelect } from 'payload';
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
3
|
+
import type { Context } from '../resolvers/types.js';
|
|
4
|
+
export declare function buildSelectForCollection(info: GraphQLResolveInfo, context?: Context): SelectType;
|
|
5
|
+
export declare function buildSelectForCollectionMany(info: GraphQLResolveInfo, context?: Context): SelectType;
|
|
6
|
+
export declare function resolveSelect(info: GraphQLResolveInfo, select: SelectType, context?: Context): SelectType;
|
|
6
7
|
type SelectType = TypedCollectionSelect['any'];
|
|
7
8
|
export {};
|
|
8
9
|
//# sourceMappingURL=select.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/utilities/select.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,kBAAkB,EAAoB,MAAM,SAAS,CAAA;AACtF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/utilities/select.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,kBAAkB,EAAoB,MAAM,SAAS,CAAA;AACtF,OAAO,KAAK,EAKV,qBAAqB,EAEtB,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AASpD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,UAAU,CAMhG;AACD,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,kBAAkB,EACxB,OAAO,CAAC,EAAE,OAAO,GAChB,UAAU,CAMZ;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE,OAAO,GAChB,UAAU,CA0BZ;AA+JD,KAAK,UAAU,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAA"}
|
package/dist/utilities/select.js
CHANGED
|
@@ -1,52 +1,47 @@
|
|
|
1
1
|
import { getNamedType, isInterfaceType, isObjectType, isUnionType, Kind } from 'graphql';
|
|
2
|
-
|
|
2
|
+
const selectRootPathsByContext = new WeakMap();
|
|
3
|
+
export function buildSelectForCollection(info, context) {
|
|
4
|
+
if (context) {
|
|
5
|
+
registerSelectRootPath(context, info);
|
|
6
|
+
}
|
|
3
7
|
return buildSelect(info);
|
|
4
8
|
}
|
|
5
|
-
export function buildSelectForCollectionMany(info) {
|
|
6
|
-
|
|
9
|
+
export function buildSelectForCollectionMany(info, context) {
|
|
10
|
+
if (context) {
|
|
11
|
+
registerSelectRootPath(context, info);
|
|
12
|
+
}
|
|
13
|
+
return buildSelect(info)?.docs;
|
|
7
14
|
}
|
|
8
|
-
export function resolveSelect(info, select) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const pathKey = path.key;
|
|
13
|
-
const pathType = info.schema.getType(path.typename);
|
|
14
|
-
if (pathType) {
|
|
15
|
-
const field = pathType?.getFields()?.[pathKey]?.extensions?.field;
|
|
16
|
-
if (field?.type === 'join') {
|
|
17
|
-
path = path.prev;
|
|
18
|
-
traversePath.unshift('docs');
|
|
19
|
-
}
|
|
20
|
-
if (field?.type === 'relationship' && Array.isArray(field.relationTo)) {
|
|
21
|
-
path = path.prev;
|
|
22
|
-
traversePath.unshift('value');
|
|
23
|
-
}
|
|
24
|
-
if (field) {
|
|
25
|
-
traversePath.unshift(field.name);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (path.prev) {
|
|
29
|
-
traverseTree(path.prev);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
traverseTree(info.path);
|
|
33
|
-
traversePath.forEach((key)=>{
|
|
34
|
-
select = select?.[key];
|
|
35
|
-
});
|
|
15
|
+
export function resolveSelect(info, select, context) {
|
|
16
|
+
const isSelectEnabled = context ? hasSelectRootPath(context, info) : typeof select !== 'undefined';
|
|
17
|
+
if (!isSelectEnabled) {
|
|
18
|
+
return undefined;
|
|
36
19
|
}
|
|
37
|
-
|
|
20
|
+
const field = info.parentType.getFields()[info.fieldName]?.extensions?.field;
|
|
21
|
+
const fieldSelect = buildSelect(info);
|
|
22
|
+
if (field?.type === 'join') {
|
|
23
|
+
return fieldSelect?.docs;
|
|
24
|
+
}
|
|
25
|
+
if ((field?.type === 'relationship' || field?.type === 'upload') && Array.isArray(field.relationTo)) {
|
|
26
|
+
return fieldSelect?.value;
|
|
27
|
+
}
|
|
28
|
+
return fieldSelect;
|
|
38
29
|
}
|
|
39
30
|
function buildSelect(info) {
|
|
40
31
|
const returnType = getNamedType(info.returnType);
|
|
41
|
-
const selectionSet = info.fieldNodes[0].selectionSet;
|
|
42
32
|
if (!returnType) {
|
|
43
33
|
return;
|
|
44
34
|
}
|
|
45
|
-
return
|
|
35
|
+
return info.fieldNodes.reduce((fieldTree, fieldNode)=>{
|
|
36
|
+
if (!fieldNode.selectionSet) {
|
|
37
|
+
return fieldTree;
|
|
38
|
+
}
|
|
39
|
+
return mergeSelectTrees(fieldTree, buildSelectTree(info, fieldNode.selectionSet, returnType));
|
|
40
|
+
}, {});
|
|
46
41
|
}
|
|
47
42
|
function buildSelectTree(info, selectionSet, type) {
|
|
48
43
|
const fieldMap = type.getFields?.();
|
|
49
|
-
|
|
44
|
+
let fieldTree = {};
|
|
50
45
|
for (const selection of selectionSet.selections){
|
|
51
46
|
switch(selection.kind){
|
|
52
47
|
case Kind.FIELD:
|
|
@@ -64,11 +59,15 @@ function buildSelectTree(info, selectionSet, type) {
|
|
|
64
59
|
if (selection.selectionSet) {
|
|
65
60
|
const type = getNamedType(fieldSchema.type);
|
|
66
61
|
if (isObjectType(type) || isInterfaceType(type) || isUnionType(type)) {
|
|
67
|
-
fieldTree
|
|
62
|
+
fieldTree = mergeSelectTrees(fieldTree, {
|
|
63
|
+
[fieldNameOriginal]: buildSelectTree(info, selection.selectionSet, type)
|
|
64
|
+
});
|
|
68
65
|
continue;
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
|
-
fieldTree
|
|
68
|
+
fieldTree = mergeSelectTrees(fieldTree, {
|
|
69
|
+
[fieldNameOriginal]: true
|
|
70
|
+
});
|
|
72
71
|
break;
|
|
73
72
|
}
|
|
74
73
|
case Kind.FRAGMENT_SPREAD:
|
|
@@ -77,7 +76,7 @@ function buildSelectTree(info, selectionSet, type) {
|
|
|
77
76
|
const fragment = info.fragments[fragmentName];
|
|
78
77
|
const fragmentType = fragment && info.schema.getType(fragment.typeCondition.name.value);
|
|
79
78
|
if (fragmentType) {
|
|
80
|
-
|
|
79
|
+
fieldTree = mergeSelectTrees(fieldTree, buildFragmentSelectTree(info, fragment.selectionSet, fragmentType, type));
|
|
81
80
|
}
|
|
82
81
|
break;
|
|
83
82
|
}
|
|
@@ -85,13 +84,7 @@ function buildSelectTree(info, selectionSet, type) {
|
|
|
85
84
|
{
|
|
86
85
|
const fragmentType = selection.typeCondition ? info.schema.getType(selection.typeCondition.name.value) : type;
|
|
87
86
|
if (fragmentType) {
|
|
88
|
-
|
|
89
|
-
const blockSlug = fragmentType.extensions?.blockSlug;
|
|
90
|
-
if (blockSlug && isUnionType(type)) {
|
|
91
|
-
fieldTree[blockSlug] = buildSelectTree(info, selection.selectionSet, fragmentType);
|
|
92
|
-
} else {
|
|
93
|
-
Object.assign(fieldTree, buildSelectTree(info, selection.selectionSet, fragmentType));
|
|
94
|
-
}
|
|
87
|
+
fieldTree = mergeSelectTrees(fieldTree, buildFragmentSelectTree(info, selection.selectionSet, fragmentType, type));
|
|
95
88
|
}
|
|
96
89
|
break;
|
|
97
90
|
}
|
|
@@ -99,5 +92,50 @@ function buildSelectTree(info, selectionSet, type) {
|
|
|
99
92
|
}
|
|
100
93
|
return fieldTree;
|
|
101
94
|
}
|
|
95
|
+
function buildFragmentSelectTree(info, selectionSet, fragmentType, parentType) {
|
|
96
|
+
const fragmentSelectTree = buildSelectTree(info, selectionSet, fragmentType);
|
|
97
|
+
const blockSlug = fragmentType.extensions?.blockSlug;
|
|
98
|
+
if (blockSlug && isUnionType(parentType)) {
|
|
99
|
+
return {
|
|
100
|
+
[blockSlug]: fragmentSelectTree
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return fragmentSelectTree;
|
|
104
|
+
}
|
|
105
|
+
function getRootPathKey(path) {
|
|
106
|
+
while(path.prev){
|
|
107
|
+
path = path.prev;
|
|
108
|
+
}
|
|
109
|
+
return path.key;
|
|
110
|
+
}
|
|
111
|
+
function hasSelectRootPath(context, info) {
|
|
112
|
+
return Boolean(selectRootPathsByContext.get(context)?.get(info.operation)?.has(getRootPathKey(info.path)));
|
|
113
|
+
}
|
|
114
|
+
function isSelectTree(value) {
|
|
115
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
116
|
+
}
|
|
117
|
+
function mergeSelectTrees(firstTree, secondTree) {
|
|
118
|
+
const mergedTree = {
|
|
119
|
+
...firstTree
|
|
120
|
+
};
|
|
121
|
+
for (const [fieldName, fieldSelect] of Object.entries(secondTree)){
|
|
122
|
+
const existingFieldSelect = mergedTree[fieldName];
|
|
123
|
+
mergedTree[fieldName] = isSelectTree(existingFieldSelect) && isSelectTree(fieldSelect) ? mergeSelectTrees(existingFieldSelect, fieldSelect) : fieldSelect;
|
|
124
|
+
}
|
|
125
|
+
return mergedTree;
|
|
126
|
+
}
|
|
127
|
+
function registerSelectRootPath(context, info) {
|
|
128
|
+
let selectRootPathsByOperation = selectRootPathsByContext.get(context);
|
|
129
|
+
if (!selectRootPathsByOperation) {
|
|
130
|
+
selectRootPathsByOperation = new WeakMap();
|
|
131
|
+
selectRootPathsByContext.set(context, selectRootPathsByOperation);
|
|
132
|
+
}
|
|
133
|
+
let selectRootPaths = selectRootPathsByOperation.get(info.operation);
|
|
134
|
+
if (!selectRootPaths) {
|
|
135
|
+
selectRootPaths = new Set();
|
|
136
|
+
selectRootPathsByOperation.set(info.operation, selectRootPaths);
|
|
137
|
+
}
|
|
138
|
+
selectRootPaths.add(getRootPathKey(info.path));
|
|
139
|
+
}
|
|
102
140
|
|
|
103
141
|
//# sourceMappingURL=select.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/select.ts"],"sourcesContent":["import type { GraphQLObjectType, GraphQLResolveInfo, SelectionSetNode } from 'graphql'\nimport type { FieldBase, JoinField, RelationshipField, TypedCollectionSelect } from 'payload'\n\nimport { getNamedType, isInterfaceType, isObjectType, isUnionType, Kind } from 'graphql'\n\nexport function buildSelectForCollection(info: GraphQLResolveInfo): SelectType {\n return buildSelect(info)\n}\nexport function buildSelectForCollectionMany(info: GraphQLResolveInfo): SelectType {\n return buildSelect(info).docs as SelectType\n}\n\nexport function resolveSelect(info: GraphQLResolveInfo, select: SelectType): SelectType {\n if (select) {\n const traversePath: string[] = []\n const traverseTree = (path: GraphQLResolveInfo['path']) => {\n const pathKey = path.key\n const pathType = info.schema.getType(path.typename) as GraphQLObjectType\n\n if (pathType) {\n const field = pathType?.getFields()?.[pathKey]?.extensions?.field as\n | JoinField\n | RelationshipField\n\n if (field?.type === 'join') {\n path = path.prev\n traversePath.unshift('docs')\n }\n if (field?.type === 'relationship' && Array.isArray(field.relationTo)) {\n path = path.prev\n traversePath.unshift('value')\n }\n if (field) {\n traversePath.unshift(field.name)\n }\n }\n\n if (path.prev) {\n traverseTree(path.prev)\n }\n }\n\n traverseTree(info.path)\n traversePath.forEach((key) => {\n select = select?.[key] as SelectType\n })\n }\n\n return select\n}\n\nfunction buildSelect(info: GraphQLResolveInfo) {\n const returnType = getNamedType(info.returnType) as GraphQLObjectType\n const selectionSet = info.fieldNodes[0].selectionSet\n\n if (!returnType) {\n return\n }\n\n return buildSelectTree(info, selectionSet, returnType)\n}\nfunction buildSelectTree(\n info: GraphQLResolveInfo,\n selectionSet: SelectionSetNode,\n type: GraphQLObjectType,\n): SelectType {\n const fieldMap = type.getFields?.()\n const fieldTree: SelectType = {}\n\n for (const selection of selectionSet.selections) {\n switch (selection.kind) {\n case Kind.FIELD: {\n const fieldName = selection.name.value\n const fieldSchema = fieldMap?.[fieldName]\n\n const field = fieldSchema?.extensions?.field as FieldBase\n const fieldNameOriginal = field?.name || fieldName\n\n if (fieldName === '__typename') {\n continue\n }\n if (fieldSchema == undefined) {\n continue\n }\n\n if (selection.selectionSet) {\n const type = getNamedType(fieldSchema.type) as GraphQLObjectType\n\n if (isObjectType(type) || isInterfaceType(type) || isUnionType(type)) {\n fieldTree[fieldNameOriginal] = buildSelectTree(info, selection.selectionSet, type)\n continue\n }\n }\n\n fieldTree[fieldNameOriginal] = true\n break\n }\n\n case Kind.FRAGMENT_SPREAD: {\n const fragmentName = selection.name.value\n const fragment = info.fragments[fragmentName]\n const fragmentType =\n fragment && (info.schema.getType(fragment.typeCondition.name.value) as GraphQLObjectType)\n\n if (fragmentType) {\n Object.assign(fieldTree, buildSelectTree(info, fragment.selectionSet, fragmentType))\n }\n break\n }\n\n case Kind.INLINE_FRAGMENT: {\n const fragmentType = selection.typeCondition\n ? (info.schema.getType(selection.typeCondition.name.value) as GraphQLObjectType)\n : type\n\n if (fragmentType) {\n // Block types in unions need selections nested under their slug\n const blockSlug = fragmentType.extensions?.blockSlug as string | undefined\n\n if (blockSlug && isUnionType(type)) {\n fieldTree[blockSlug] = buildSelectTree(info, selection.selectionSet, fragmentType)\n } else {\n Object.assign(fieldTree, buildSelectTree(info, selection.selectionSet, fragmentType))\n }\n }\n break\n }\n }\n }\n\n return fieldTree\n}\n\ntype SelectType = TypedCollectionSelect['any']\n"],"names":["getNamedType","isInterfaceType","isObjectType","isUnionType","Kind","buildSelectForCollection","info","buildSelect","buildSelectForCollectionMany","docs","resolveSelect","select","traversePath","traverseTree","path","pathKey","key","pathType","schema","getType","typename","field","getFields","extensions","type","prev","unshift","Array","isArray","relationTo","name","forEach","returnType","selectionSet","fieldNodes","buildSelectTree","fieldMap","fieldTree","selection","selections","kind","FIELD","fieldName","value","fieldSchema","fieldNameOriginal","undefined","FRAGMENT_SPREAD","fragmentName","fragment","fragments","fragmentType","typeCondition","Object","assign","INLINE_FRAGMENT","blockSlug"],"mappings":"AAGA,SAASA,YAAY,EAAEC,eAAe,EAAEC,YAAY,EAAEC,WAAW,EAAEC,IAAI,QAAQ,UAAS;AAExF,OAAO,SAASC,yBAAyBC,IAAwB;IAC/D,OAAOC,YAAYD;AACrB;AACA,OAAO,SAASE,6BAA6BF,IAAwB;IACnE,OAAOC,YAAYD,MAAMG,IAAI;AAC/B;AAEA,OAAO,SAASC,cAAcJ,IAAwB,EAAEK,MAAkB;IACxE,IAAIA,QAAQ;QACV,MAAMC,eAAyB,EAAE;QACjC,MAAMC,eAAe,CAACC;YACpB,MAAMC,UAAUD,KAAKE,GAAG;YACxB,MAAMC,WAAWX,KAAKY,MAAM,CAACC,OAAO,CAACL,KAAKM,QAAQ;YAElD,IAAIH,UAAU;gBACZ,MAAMI,QAAQJ,UAAUK,aAAa,CAACP,QAAQ,EAAEQ,YAAYF;gBAI5D,IAAIA,OAAOG,SAAS,QAAQ;oBAC1BV,OAAOA,KAAKW,IAAI;oBAChBb,aAAac,OAAO,CAAC;gBACvB;gBACA,IAAIL,OAAOG,SAAS,kBAAkBG,MAAMC,OAAO,CAACP,MAAMQ,UAAU,GAAG;oBACrEf,OAAOA,KAAKW,IAAI;oBAChBb,aAAac,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SAAS,CAACQ,kBAAkB,GAAG;oBAC/B;gBACF;YAEA,KAAKzC,KAAK2C,eAAe;gBAAE;oBACzB,MAAMC,eAAeV,UAAUR,IAAI,CAACa,KAAK;oBACzC,MAAMM,WAAW3C,KAAK4C,SAAS,CAACF,aAAa;oBAC7C,MAAMG,eACJF,YAAa3C,KAAKY,MAAM,CAACC,OAAO,CAAC8B,SAASG,aAAa,CAACtB,IAAI,CAACa,KAAK;oBAEpE,IAAIQ,cAAc;wBAChBE,OAAOC,MAAM,CAACjB,WAAWF,gBAAgB7B,MAAM2C,SAAShB,YAAY,EAAEkB;oBACxE;oBACA;gBACF;YAEA,KAAK/C,KAAKmD,eAAe;gBAAE;oBACzB,MAAMJ,eAAeb,UAAUc,aAAa,GACvC9C,KAAKY,MAAM,CAACC,OAAO,CAACmB,UAAUc,aAAa,CAACtB,IAAI,CAACa,KAAK,IACvDnB;oBAEJ,IAAI2B,cAAc;wBAChB,gEAAgE;wBAChE,MAAMK,YAAYL,aAAa5B,UAAU,EAAEiC;wBAE3C,IAAIA,aAAarD,YAAYqB,OAAO;4BAClCa,SAAS,CAACmB,UAAU,GAAGrB,gBAAgB7B,MAAMgC,UAAUL,YAAY,EAAEkB;wBACvE,OAAO;4BACLE,OAAOC,MAAM,CAACjB,WAAWF,gBAAgB7B,MAAMgC,UAAUL,YAAY,EAAEkB;wBACzE;oBACF;oBACA;gBACF;QACF;IACF;IAEA,OAAOd;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/select.ts"],"sourcesContent":["import type { GraphQLObjectType, GraphQLResolveInfo, SelectionSetNode } from 'graphql'\nimport type {\n FieldBase,\n JoinField,\n RelationshipField,\n SelectIncludeType,\n TypedCollectionSelect,\n UploadField,\n} from 'payload'\n\nimport { getNamedType, isInterfaceType, isObjectType, isUnionType, Kind } from 'graphql'\n\nimport type { Context } from '../resolvers/types.js'\n\ntype SelectRootPathsByOperation = WeakMap<\n GraphQLResolveInfo['operation'],\n Set<GraphQLResolveInfo['path']['key']>\n>\n\nconst selectRootPathsByContext = new WeakMap<Context, SelectRootPathsByOperation>()\n\nexport function buildSelectForCollection(info: GraphQLResolveInfo, context?: Context): SelectType {\n if (context) {\n registerSelectRootPath(context, info)\n }\n\n return buildSelect(info)\n}\nexport function buildSelectForCollectionMany(\n info: GraphQLResolveInfo,\n context?: Context,\n): SelectType {\n if (context) {\n registerSelectRootPath(context, info)\n }\n\n return buildSelect(info)?.docs as SelectType\n}\n\nexport function resolveSelect(\n info: GraphQLResolveInfo,\n select: SelectType,\n context?: Context,\n): SelectType {\n const isSelectEnabled = context ? hasSelectRootPath(context, info) : typeof select !== 'undefined'\n\n if (!isSelectEnabled) {\n return undefined\n }\n\n const field = info.parentType.getFields()[info.fieldName]?.extensions?.field as\n | JoinField\n | RelationshipField\n | undefined\n | UploadField\n const fieldSelect = buildSelect(info)\n\n if (field?.type === 'join') {\n return fieldSelect?.docs as SelectType\n }\n\n if (\n (field?.type === 'relationship' || field?.type === 'upload') &&\n Array.isArray(field.relationTo)\n ) {\n return fieldSelect?.value as SelectType\n }\n\n return fieldSelect\n}\n\nfunction buildSelect(info: GraphQLResolveInfo) {\n const returnType = getNamedType(info.returnType) as GraphQLObjectType\n\n if (!returnType) {\n return\n }\n\n return info.fieldNodes.reduce<SelectTree>((fieldTree, fieldNode) => {\n if (!fieldNode.selectionSet) {\n return fieldTree\n }\n\n return mergeSelectTrees(fieldTree, buildSelectTree(info, fieldNode.selectionSet, returnType))\n }, {})\n}\n\nfunction buildSelectTree(\n info: GraphQLResolveInfo,\n selectionSet: SelectionSetNode,\n type: GraphQLObjectType,\n): SelectTree {\n const fieldMap = type.getFields?.()\n let fieldTree: SelectTree = {}\n\n for (const selection of selectionSet.selections) {\n switch (selection.kind) {\n case Kind.FIELD: {\n const fieldName = selection.name.value\n const fieldSchema = fieldMap?.[fieldName]\n\n const field = fieldSchema?.extensions?.field as FieldBase\n const fieldNameOriginal = field?.name || fieldName\n\n if (fieldName === '__typename') {\n continue\n }\n if (fieldSchema == undefined) {\n continue\n }\n\n if (selection.selectionSet) {\n const type = getNamedType(fieldSchema.type) as GraphQLObjectType\n\n if (isObjectType(type) || isInterfaceType(type) || isUnionType(type)) {\n fieldTree = mergeSelectTrees(fieldTree, {\n [fieldNameOriginal]: buildSelectTree(info, selection.selectionSet, type),\n })\n continue\n }\n }\n\n fieldTree = mergeSelectTrees(fieldTree, { [fieldNameOriginal]: true })\n break\n }\n\n case Kind.FRAGMENT_SPREAD: {\n const fragmentName = selection.name.value\n const fragment = info.fragments[fragmentName]\n const fragmentType =\n fragment && (info.schema.getType(fragment.typeCondition.name.value) as GraphQLObjectType)\n\n if (fragmentType) {\n fieldTree = mergeSelectTrees(\n fieldTree,\n buildFragmentSelectTree(info, fragment.selectionSet, fragmentType, type),\n )\n }\n break\n }\n\n case Kind.INLINE_FRAGMENT: {\n const fragmentType = selection.typeCondition\n ? (info.schema.getType(selection.typeCondition.name.value) as GraphQLObjectType)\n : type\n\n if (fragmentType) {\n fieldTree = mergeSelectTrees(\n fieldTree,\n buildFragmentSelectTree(info, selection.selectionSet, fragmentType, type),\n )\n }\n break\n }\n }\n }\n\n return fieldTree\n}\n\nfunction buildFragmentSelectTree(\n info: GraphQLResolveInfo,\n selectionSet: SelectionSetNode,\n fragmentType: GraphQLObjectType,\n parentType: GraphQLObjectType,\n): SelectTree {\n const fragmentSelectTree = buildSelectTree(info, selectionSet, fragmentType)\n const blockSlug = fragmentType.extensions?.blockSlug as string | undefined\n\n if (blockSlug && isUnionType(parentType)) {\n return { [blockSlug]: fragmentSelectTree }\n }\n\n return fragmentSelectTree\n}\n\nfunction getRootPathKey(path: GraphQLResolveInfo['path']): GraphQLResolveInfo['path']['key'] {\n while (path.prev) {\n path = path.prev\n }\n\n return path.key\n}\n\nfunction hasSelectRootPath(context: Context, info: GraphQLResolveInfo): boolean {\n return Boolean(\n selectRootPathsByContext.get(context)?.get(info.operation)?.has(getRootPathKey(info.path)),\n )\n}\n\nfunction isSelectTree(value: unknown): value is SelectTree {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction mergeSelectTrees(firstTree: SelectTree, secondTree: SelectTree): SelectTree {\n const mergedTree = { ...firstTree }\n\n for (const [fieldName, fieldSelect] of Object.entries(secondTree)) {\n const existingFieldSelect = mergedTree[fieldName]\n\n mergedTree[fieldName] =\n isSelectTree(existingFieldSelect) && isSelectTree(fieldSelect)\n ? mergeSelectTrees(existingFieldSelect, fieldSelect)\n : fieldSelect\n }\n\n return mergedTree\n}\n\nfunction registerSelectRootPath(context: Context, info: GraphQLResolveInfo): void {\n let selectRootPathsByOperation = selectRootPathsByContext.get(context)\n\n if (!selectRootPathsByOperation) {\n selectRootPathsByOperation = new WeakMap()\n selectRootPathsByContext.set(context, selectRootPathsByOperation)\n }\n\n let selectRootPaths = selectRootPathsByOperation.get(info.operation)\n\n if (!selectRootPaths) {\n selectRootPaths = new Set()\n selectRootPathsByOperation.set(info.operation, selectRootPaths)\n }\n\n selectRootPaths.add(getRootPathKey(info.path))\n}\n\ntype SelectTree = SelectIncludeType\ntype SelectType = TypedCollectionSelect['any']\n"],"names":["getNamedType","isInterfaceType","isObjectType","isUnionType","Kind","selectRootPathsByContext","WeakMap","buildSelectForCollection","info","context","registerSelectRootPath","buildSelect","buildSelectForCollectionMany","docs","resolveSelect","select","isSelectEnabled","hasSelectRootPath","undefined","field","parentType","getFields","fieldName","extensions","fieldSelect","type","Array","isArray","relationTo","value","returnType","fieldNodes","reduce","fieldTree","fieldNode","selectionSet","mergeSelectTrees","buildSelectTree","fieldMap","selection","selections","kind","FIELD","name","fieldSchema","fieldNameOriginal","FRAGMENT_SPREAD","fragmentName","fragment","fragments","fragmentType","schema","getType","typeCondition","buildFragmentSelectTree","INLINE_FRAGMENT","fragmentSelectTree","blockSlug","getRootPathKey","path","prev","key","Boolean","get","operation","has","isSelectTree","firstTree","secondTree","mergedTree","Object","entries","existingFieldSelect","selectRootPathsByOperation","set","selectRootPaths","Set","add"],"mappings":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,OAAO6C;AACT;AAEA,SAAS3D,uBAAuBD,OAAgB,EAAED,IAAwB;IACxE,IAAIiE,6BAA6BpE,yBAAyB0D,GAAG,CAACtD;IAE9D,IAAI,CAACgE,4BAA4B;QAC/BA,6BAA6B,IAAInE;QACjCD,yBAAyBqE,GAAG,CAACjE,SAASgE;IACxC;IAEA,IAAIE,kBAAkBF,2BAA2BV,GAAG,CAACvD,KAAKwD,SAAS;IAEnE,IAAI,CAACW,iBAAiB;QACpBA,kBAAkB,IAAIC;QACtBH,2BAA2BC,GAAG,CAAClE,KAAKwD,SAAS,EAAEW;IACjD;IAEAA,gBAAgBE,GAAG,CAACnB,eAAelD,KAAKmD,IAAI;AAC9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/graphql",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.44ac9c8",
|
|
4
4
|
"homepage": "https://payloadcms.com",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"@types/pluralize": "^0.0.33",
|
|
54
54
|
"graphql-http": "1.22.4",
|
|
55
55
|
"@payloadcms/eslint-config": "3.28.0",
|
|
56
|
-
"payload": "4.0.0-internal.
|
|
56
|
+
"payload": "4.0.0-internal.44ac9c8"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"graphql": "^16.8.1",
|
|
60
|
-
"payload": "4.0.0-internal.
|
|
60
|
+
"payload": "4.0.0-internal.44ac9c8"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "pnpm build:types && pnpm build:swc",
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { formatName } from './formatName';
|
|
3
|
-
describe('formatName', ()=>{
|
|
4
|
-
it.each`
|
|
5
|
-
char | expected
|
|
6
|
-
${'á'} | ${'a'}
|
|
7
|
-
${'è'} | ${'e'}
|
|
8
|
-
${'í'} | ${'i'}
|
|
9
|
-
${'ó'} | ${'o'}
|
|
10
|
-
${'ú'} | ${'u'}
|
|
11
|
-
${'ñ'} | ${'n'}
|
|
12
|
-
${'ü'} | ${'u'}
|
|
13
|
-
`('should convert accented character: $char', ({ char, expected })=>{
|
|
14
|
-
expect(formatName(char)).toEqual(expected);
|
|
15
|
-
});
|
|
16
|
-
describe('UTC offset handling', ()=>{
|
|
17
|
-
it.each`
|
|
18
|
-
offset | expected
|
|
19
|
-
${'+00:00'} | ${'_TZOFFSET_PLUS_00_00'}
|
|
20
|
-
${'+05:30'} | ${'_TZOFFSET_PLUS_05_30'}
|
|
21
|
-
${'+05:45'} | ${'_TZOFFSET_PLUS_05_45'}
|
|
22
|
-
${'+08:00'} | ${'_TZOFFSET_PLUS_08_00'}
|
|
23
|
-
${'+12:00'} | ${'_TZOFFSET_PLUS_12_00'}
|
|
24
|
-
${'+14:00'} | ${'_TZOFFSET_PLUS_14_00'}
|
|
25
|
-
${'-00:00'} | ${'_TZOFFSET_MINUS_00_00'}
|
|
26
|
-
${'-03:30'} | ${'_TZOFFSET_MINUS_03_30'}
|
|
27
|
-
${'-05:00'} | ${'_TZOFFSET_MINUS_05_00'}
|
|
28
|
-
${'-08:00'} | ${'_TZOFFSET_MINUS_08_00'}
|
|
29
|
-
${'-12:00'} | ${'_TZOFFSET_MINUS_12_00'}
|
|
30
|
-
`('should convert UTC offset $offset to $expected', ({ offset, expected })=>{
|
|
31
|
-
expect(formatName(offset)).toEqual(expected);
|
|
32
|
-
});
|
|
33
|
-
it('should not collide between positive and negative offsets', ()=>{
|
|
34
|
-
const plusFive = formatName('+05:00');
|
|
35
|
-
const minusFive = formatName('-05:00');
|
|
36
|
-
expect(plusFive).not.toEqual(minusFive);
|
|
37
|
-
expect(plusFive).toEqual('_TZOFFSET_PLUS_05_00');
|
|
38
|
-
expect(minusFive).toEqual('_TZOFFSET_MINUS_05_00');
|
|
39
|
-
});
|
|
40
|
-
it('should not treat IANA timezone names as offsets', ()=>{
|
|
41
|
-
// These should use standard formatting, not UTC offset formatting
|
|
42
|
-
expect(formatName('America/New_York')).toEqual('America_New_York');
|
|
43
|
-
expect(formatName('Europe/London')).toEqual('Europe_London');
|
|
44
|
-
expect(formatName('Asia/Tokyo')).toEqual('Asia_Tokyo');
|
|
45
|
-
});
|
|
46
|
-
it('should not treat partial offset patterns as offsets', ()=>{
|
|
47
|
-
// These don't match the strict ±HH:mm pattern, so they use standard formatting
|
|
48
|
-
expect(formatName('+5')).toEqual('_5');
|
|
49
|
-
expect(formatName('+05')).toEqual('_05');
|
|
50
|
-
expect(formatName('+0530')).toEqual('_0530');
|
|
51
|
-
// 05:30 without sign is not a UTC offset, starts with number so gets _ prefix
|
|
52
|
-
expect(formatName('05:30')).toEqual('_05:30');
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
//# sourceMappingURL=formatName.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/formatName.spec.ts"],"sourcesContent":["import { describe, it, expect } from 'vitest'\nimport { formatName } from './formatName'\n\ndescribe('formatName', () => {\n it.each`\n char | expected\n ${'á'} | ${'a'}\n ${'è'} | ${'e'}\n ${'í'} | ${'i'}\n ${'ó'} | ${'o'}\n ${'ú'} | ${'u'}\n ${'ñ'} | ${'n'}\n ${'ü'} | ${'u'}\n `('should convert accented character: $char', ({ char, expected }) => {\n expect(formatName(char)).toEqual(expected)\n })\n\n describe('UTC offset handling', () => {\n it.each`\n offset | expected\n ${'+00:00'} | ${'_TZOFFSET_PLUS_00_00'}\n ${'+05:30'} | ${'_TZOFFSET_PLUS_05_30'}\n ${'+05:45'} | ${'_TZOFFSET_PLUS_05_45'}\n ${'+08:00'} | ${'_TZOFFSET_PLUS_08_00'}\n ${'+12:00'} | ${'_TZOFFSET_PLUS_12_00'}\n ${'+14:00'} | ${'_TZOFFSET_PLUS_14_00'}\n ${'-00:00'} | ${'_TZOFFSET_MINUS_00_00'}\n ${'-03:30'} | ${'_TZOFFSET_MINUS_03_30'}\n ${'-05:00'} | ${'_TZOFFSET_MINUS_05_00'}\n ${'-08:00'} | ${'_TZOFFSET_MINUS_08_00'}\n ${'-12:00'} | ${'_TZOFFSET_MINUS_12_00'}\n `('should convert UTC offset $offset to $expected', ({ offset, expected }) => {\n expect(formatName(offset)).toEqual(expected)\n })\n\n it('should not collide between positive and negative offsets', () => {\n const plusFive = formatName('+05:00')\n const minusFive = formatName('-05:00')\n expect(plusFive).not.toEqual(minusFive)\n expect(plusFive).toEqual('_TZOFFSET_PLUS_05_00')\n expect(minusFive).toEqual('_TZOFFSET_MINUS_05_00')\n })\n\n it('should not treat IANA timezone names as offsets', () => {\n // These should use standard formatting, not UTC offset formatting\n expect(formatName('America/New_York')).toEqual('America_New_York')\n expect(formatName('Europe/London')).toEqual('Europe_London')\n expect(formatName('Asia/Tokyo')).toEqual('Asia_Tokyo')\n })\n\n it('should not treat partial offset patterns as offsets', () => {\n // These don't match the strict ±HH:mm pattern, so they use standard formatting\n expect(formatName('+5')).toEqual('_5')\n expect(formatName('+05')).toEqual('_05')\n expect(formatName('+0530')).toEqual('_0530')\n // 05:30 without sign is not a UTC offset, starts with number so gets _ prefix\n expect(formatName('05:30')).toEqual('_05:30')\n })\n })\n})\n"],"names":["describe","it","expect","formatName","each","char","expected","toEqual","offset","plusFive","minusFive","not"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,QAAQ,SAAQ;AAC7C,SAASC,UAAU,QAAQ,eAAc;AAEzCH,SAAS,cAAc;IACrBC,GAAGG,IAAI,CAAC;;IAEN,EAAE,IAAI,GAAG,EAAE,IAAI;IACf,EAAE,IAAI,GAAG,EAAE,IAAI;IACf,EAAE,IAAI,GAAG,EAAE,IAAI;IACf,EAAE,IAAI,GAAG,EAAE,IAAI;IACf,EAAE,IAAI,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AO,CAAC;YACjCL,OAAOC,WAAW,QAAQI,OAAO,CAAC;YAClCL,OAAOC,WAAW,UAAUI,OAAO,CAAC;YACpC,8EAA8E;YAC9EL,OAAOC,WAAW,UAAUI,OAAO,CAAC;QACtC;IACF;AACF"}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { formatUtcOffset } from './formatUtcOffset.js';
|
|
3
|
-
describe('formatUtcOffset', ()=>{
|
|
4
|
-
describe('valid UTC offsets', ()=>{
|
|
5
|
-
it.each([
|
|
6
|
-
[
|
|
7
|
-
'+00:00',
|
|
8
|
-
'_TZOFFSET_PLUS_00_00'
|
|
9
|
-
],
|
|
10
|
-
[
|
|
11
|
-
'+05:30',
|
|
12
|
-
'_TZOFFSET_PLUS_05_30'
|
|
13
|
-
],
|
|
14
|
-
[
|
|
15
|
-
'+05:45',
|
|
16
|
-
'_TZOFFSET_PLUS_05_45'
|
|
17
|
-
],
|
|
18
|
-
[
|
|
19
|
-
'+08:00',
|
|
20
|
-
'_TZOFFSET_PLUS_08_00'
|
|
21
|
-
],
|
|
22
|
-
[
|
|
23
|
-
'+09:30',
|
|
24
|
-
'_TZOFFSET_PLUS_09_30'
|
|
25
|
-
],
|
|
26
|
-
[
|
|
27
|
-
'+12:00',
|
|
28
|
-
'_TZOFFSET_PLUS_12_00'
|
|
29
|
-
],
|
|
30
|
-
[
|
|
31
|
-
'+14:00',
|
|
32
|
-
'_TZOFFSET_PLUS_14_00'
|
|
33
|
-
]
|
|
34
|
-
])('should convert positive offset %s to %s', (offset, expected)=>{
|
|
35
|
-
expect(formatUtcOffset(offset)).toEqual(expected);
|
|
36
|
-
});
|
|
37
|
-
it.each([
|
|
38
|
-
[
|
|
39
|
-
'-00:00',
|
|
40
|
-
'_TZOFFSET_MINUS_00_00'
|
|
41
|
-
],
|
|
42
|
-
[
|
|
43
|
-
'-03:30',
|
|
44
|
-
'_TZOFFSET_MINUS_03_30'
|
|
45
|
-
],
|
|
46
|
-
[
|
|
47
|
-
'-05:00',
|
|
48
|
-
'_TZOFFSET_MINUS_05_00'
|
|
49
|
-
],
|
|
50
|
-
[
|
|
51
|
-
'-08:00',
|
|
52
|
-
'_TZOFFSET_MINUS_08_00'
|
|
53
|
-
],
|
|
54
|
-
[
|
|
55
|
-
'-09:30',
|
|
56
|
-
'_TZOFFSET_MINUS_09_30'
|
|
57
|
-
],
|
|
58
|
-
[
|
|
59
|
-
'-12:00',
|
|
60
|
-
'_TZOFFSET_MINUS_12_00'
|
|
61
|
-
]
|
|
62
|
-
])('should convert negative offset %s to %s', (offset, expected)=>{
|
|
63
|
-
expect(formatUtcOffset(offset)).toEqual(expected);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
describe('non-offset values', ()=>{
|
|
67
|
-
it.each([
|
|
68
|
-
'UTC',
|
|
69
|
-
'America/New_York',
|
|
70
|
-
'Europe/London',
|
|
71
|
-
'Asia/Tokyo',
|
|
72
|
-
'Pacific/Auckland'
|
|
73
|
-
])('should return null for IANA timezone: %s', (timezone)=>{
|
|
74
|
-
expect(formatUtcOffset(timezone)).toBeNull();
|
|
75
|
-
});
|
|
76
|
-
it.each([
|
|
77
|
-
'+5',
|
|
78
|
-
'-8',
|
|
79
|
-
'+05',
|
|
80
|
-
'-08',
|
|
81
|
-
'+0530',
|
|
82
|
-
'-0800',
|
|
83
|
-
'05:30',
|
|
84
|
-
'0530',
|
|
85
|
-
'invalid',
|
|
86
|
-
''
|
|
87
|
-
])('should return null for non-standard format: %s', (value)=>{
|
|
88
|
-
expect(formatUtcOffset(value)).toBeNull();
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
describe('uniqueness', ()=>{
|
|
92
|
-
it('should produce unique names for positive and negative offsets', ()=>{
|
|
93
|
-
const testCases = [
|
|
94
|
-
[
|
|
95
|
-
'+05:00',
|
|
96
|
-
'-05:00'
|
|
97
|
-
],
|
|
98
|
-
[
|
|
99
|
-
'+08:00',
|
|
100
|
-
'-08:00'
|
|
101
|
-
],
|
|
102
|
-
[
|
|
103
|
-
'+00:00',
|
|
104
|
-
'-00:00'
|
|
105
|
-
],
|
|
106
|
-
[
|
|
107
|
-
'+12:00',
|
|
108
|
-
'-12:00'
|
|
109
|
-
]
|
|
110
|
-
];
|
|
111
|
-
for (const [positive, negative] of testCases){
|
|
112
|
-
const positiveName = formatUtcOffset(positive);
|
|
113
|
-
const negativeName = formatUtcOffset(negative);
|
|
114
|
-
expect(positiveName).not.toEqual(negativeName);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
it('should produce unique names for different hour offsets', ()=>{
|
|
118
|
-
const offsets = [
|
|
119
|
-
'+05:00',
|
|
120
|
-
'+06:00',
|
|
121
|
-
'+07:00',
|
|
122
|
-
'+08:00'
|
|
123
|
-
];
|
|
124
|
-
const names = offsets.map(formatUtcOffset);
|
|
125
|
-
const uniqueNames = new Set(names);
|
|
126
|
-
expect(uniqueNames.size).toEqual(offsets.length);
|
|
127
|
-
});
|
|
128
|
-
it('should produce unique names for different minute offsets', ()=>{
|
|
129
|
-
const offsets = [
|
|
130
|
-
'+05:00',
|
|
131
|
-
'+05:15',
|
|
132
|
-
'+05:30',
|
|
133
|
-
'+05:45'
|
|
134
|
-
];
|
|
135
|
-
const names = offsets.map(formatUtcOffset);
|
|
136
|
-
const uniqueNames = new Set(names);
|
|
137
|
-
expect(uniqueNames.size).toEqual(offsets.length);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
//# sourceMappingURL=formatUtcOffset.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/formatUtcOffset.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { formatUtcOffset } from './formatUtcOffset.js'\n\ndescribe('formatUtcOffset', () => {\n describe('valid UTC offsets', () => {\n it.each([\n ['+00:00', '_TZOFFSET_PLUS_00_00'],\n ['+05:30', '_TZOFFSET_PLUS_05_30'],\n ['+05:45', '_TZOFFSET_PLUS_05_45'],\n ['+08:00', '_TZOFFSET_PLUS_08_00'],\n ['+09:30', '_TZOFFSET_PLUS_09_30'],\n ['+12:00', '_TZOFFSET_PLUS_12_00'],\n ['+14:00', '_TZOFFSET_PLUS_14_00'],\n ])('should convert positive offset %s to %s', (offset, expected) => {\n expect(formatUtcOffset(offset)).toEqual(expected)\n })\n\n it.each([\n ['-00:00', '_TZOFFSET_MINUS_00_00'],\n ['-03:30', '_TZOFFSET_MINUS_03_30'],\n ['-05:00', '_TZOFFSET_MINUS_05_00'],\n ['-08:00', '_TZOFFSET_MINUS_08_00'],\n ['-09:30', '_TZOFFSET_MINUS_09_30'],\n ['-12:00', '_TZOFFSET_MINUS_12_00'],\n ])('should convert negative offset %s to %s', (offset, expected) => {\n expect(formatUtcOffset(offset)).toEqual(expected)\n })\n })\n\n describe('non-offset values', () => {\n it.each(['UTC', 'America/New_York', 'Europe/London', 'Asia/Tokyo', 'Pacific/Auckland'])(\n 'should return null for IANA timezone: %s',\n (timezone) => {\n expect(formatUtcOffset(timezone)).toBeNull()\n },\n )\n\n it.each(['+5', '-8', '+05', '-08', '+0530', '-0800', '05:30', '0530', 'invalid', ''])(\n 'should return null for non-standard format: %s',\n (value) => {\n expect(formatUtcOffset(value)).toBeNull()\n },\n )\n })\n\n describe('uniqueness', () => {\n it('should produce unique names for positive and negative offsets', () => {\n const testCases = [\n ['+05:00', '-05:00'],\n ['+08:00', '-08:00'],\n ['+00:00', '-00:00'],\n ['+12:00', '-12:00'],\n ]\n\n for (const [positive, negative] of testCases) {\n const positiveName = formatUtcOffset(positive)\n const negativeName = formatUtcOffset(negative)\n expect(positiveName).not.toEqual(negativeName)\n }\n })\n\n it('should produce unique names for different hour offsets', () => {\n const offsets = ['+05:00', '+06:00', '+07:00', '+08:00']\n const names = offsets.map(formatUtcOffset)\n const uniqueNames = new Set(names)\n expect(uniqueNames.size).toEqual(offsets.length)\n })\n\n it('should produce unique names for different minute offsets', () => {\n const offsets = ['+05:00', '+05:15', '+05:30', '+05:45']\n const names = offsets.map(formatUtcOffset)\n const uniqueNames = new Set(names)\n expect(uniqueNames.size).toEqual(offsets.length)\n })\n })\n})\n"],"names":["describe","expect","it","formatUtcOffset","each","offset","expected","toEqual","timezone","toBeNull","value","testCases","positive","negative","positiveName","negativeName","not","offsets","names","map","uniqueNames","Set","size","length"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,eAAe,QAAQ,uBAAsB;AAEtDH,SAAS,mBAAmB;IAC1BA,SAAS,qBAAqB;QAC5BE,GAAGE,IAAI,CAAC;YACN;gBAAC;gBAAU;aAAuB;YAClC;gBAAC;gBAAU;aAAuB;YAClC;gBAAC;gBAAU;aAAuB;YAClC;gBAAC;gBAAU;aAAuB;YAClC;gBAAC;gBAAU;aAAuB;YAClC;gBAAC;gBAAU;aAAuB;YAClC;gBAAC;gBAAU;aAAuB;SACnC,EAAE,2CAA2C,CAACC,QAAQC;YACrDL,OAAOE,gBAAgBE,SAASE,OAAO,CAACD;QAC1C;QAEAJ,GAAGE,IAAI,CAAC;YACN;gBAAC;gBAAU;aAAwB;YACnC;gBAAC;gBAAU;aAAwB;YACnC;gBAAC;gBAAU;aAAwB;YACnC;gBAAC;gBAAU;aAAwB;YACnC;gBAAC;gBAAU;aAAwB;YACnC;gBAAC;gBAAU;aAAwB;SACpC,EAAE,2CAA2C,CAACC,QAAQC;YACrDL,OAAOE,gBAAgBE,SAASE,OAAO,CAACD;QAC1C;IACF;IAEAN,SAAS,qBAAqB;QAC5BE,GAAGE,IAAI,CAAC;YAAC;YAAO;YAAoB;YAAiB;YAAc;SAAmB,EACpF,4CACA,CAACI;YACCP,OAAOE,gBAAgBK,WAAWC,QAAQ;QAC5C;QAGFP,GAAGE,IAAI,CAAC;YAAC;YAAM;YAAM;YAAO;YAAO;YAAS;YAAS;YAAS;YAAQ;YAAW;SAAG,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