payload 3.0.0-beta.64 → 3.0.0-beta.66

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.
Files changed (100) hide show
  1. package/dist/auth/baseFields/accountLock.d.ts +1 -2
  2. package/dist/auth/baseFields/accountLock.d.ts.map +1 -1
  3. package/dist/auth/baseFields/accountLock.js +1 -1
  4. package/dist/auth/baseFields/accountLock.js.map +1 -1
  5. package/dist/auth/baseFields/apiKey.d.ts +1 -2
  6. package/dist/auth/baseFields/apiKey.d.ts.map +1 -1
  7. package/dist/auth/baseFields/apiKey.js +1 -2
  8. package/dist/auth/baseFields/apiKey.js.map +1 -1
  9. package/dist/auth/baseFields/auth.d.ts +1 -2
  10. package/dist/auth/baseFields/auth.d.ts.map +1 -1
  11. package/dist/auth/baseFields/auth.js +1 -2
  12. package/dist/auth/baseFields/auth.js.map +1 -1
  13. package/dist/auth/baseFields/email.d.ts +5 -0
  14. package/dist/auth/baseFields/email.d.ts.map +1 -0
  15. package/dist/auth/baseFields/email.js +25 -0
  16. package/dist/auth/baseFields/email.js.map +1 -0
  17. package/dist/auth/baseFields/username.d.ts +3 -0
  18. package/dist/auth/baseFields/username.d.ts.map +1 -0
  19. package/dist/auth/baseFields/username.js +25 -0
  20. package/dist/auth/baseFields/username.js.map +1 -0
  21. package/dist/auth/baseFields/verification.d.ts +1 -2
  22. package/dist/auth/baseFields/verification.d.ts.map +1 -1
  23. package/dist/auth/baseFields/verification.js +1 -1
  24. package/dist/auth/baseFields/verification.js.map +1 -1
  25. package/dist/auth/getAuthFields.d.ts +4 -0
  26. package/dist/auth/getAuthFields.d.ts.map +1 -0
  27. package/dist/auth/getAuthFields.js +35 -0
  28. package/dist/auth/getAuthFields.js.map +1 -0
  29. package/dist/auth/isLocked.d.ts.map +1 -1
  30. package/dist/auth/isLocked.js +4 -1
  31. package/dist/auth/isLocked.js.map +1 -1
  32. package/dist/auth/operations/forgotPassword.d.ts.map +1 -1
  33. package/dist/auth/operations/forgotPassword.js +25 -14
  34. package/dist/auth/operations/forgotPassword.js.map +1 -1
  35. package/dist/auth/operations/local/unlock.d.ts +5 -7
  36. package/dist/auth/operations/local/unlock.d.ts.map +1 -1
  37. package/dist/auth/operations/local/unlock.js.map +1 -1
  38. package/dist/auth/operations/login.d.ts.map +1 -1
  39. package/dist/auth/operations/login.js +70 -17
  40. package/dist/auth/operations/login.js.map +1 -1
  41. package/dist/auth/operations/resetPassword.d.ts +0 -1
  42. package/dist/auth/operations/resetPassword.d.ts.map +1 -1
  43. package/dist/auth/operations/resetPassword.js +0 -1
  44. package/dist/auth/operations/resetPassword.js.map +1 -1
  45. package/dist/auth/operations/unlock.d.ts +5 -7
  46. package/dist/auth/operations/unlock.d.ts.map +1 -1
  47. package/dist/auth/operations/unlock.js +22 -15
  48. package/dist/auth/operations/unlock.js.map +1 -1
  49. package/dist/auth/types.d.ts +7 -2
  50. package/dist/auth/types.d.ts.map +1 -1
  51. package/dist/auth/types.js.map +1 -1
  52. package/dist/collections/config/defaults.d.ts +2 -0
  53. package/dist/collections/config/defaults.d.ts.map +1 -1
  54. package/dist/collections/config/defaults.js +4 -0
  55. package/dist/collections/config/defaults.js.map +1 -1
  56. package/dist/collections/config/sanitize.d.ts.map +1 -1
  57. package/dist/collections/config/sanitize.js +6 -22
  58. package/dist/collections/config/sanitize.js.map +1 -1
  59. package/dist/collections/config/schema.d.ts.map +1 -1
  60. package/dist/collections/config/schema.js +4 -1
  61. package/dist/collections/config/schema.js.map +1 -1
  62. package/dist/collections/operations/create.d.ts.map +1 -1
  63. package/dist/collections/operations/create.js +1 -4
  64. package/dist/collections/operations/create.js.map +1 -1
  65. package/dist/fields/config/client.d.ts +1 -1
  66. package/dist/fields/config/client.d.ts.map +1 -1
  67. package/dist/fields/config/client.js +3 -1
  68. package/dist/fields/config/client.js.map +1 -1
  69. package/dist/fields/config/schema.d.ts.map +1 -1
  70. package/dist/fields/config/schema.js +3 -0
  71. package/dist/fields/config/schema.js.map +1 -1
  72. package/dist/fields/config/types.d.ts +9 -0
  73. package/dist/fields/config/types.d.ts.map +1 -1
  74. package/dist/fields/config/types.js.map +1 -1
  75. package/dist/fields/validations.d.ts +1 -0
  76. package/dist/fields/validations.d.ts.map +1 -1
  77. package/dist/fields/validations.js +13 -0
  78. package/dist/fields/validations.js.map +1 -1
  79. package/dist/index.d.ts +4 -2
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  83. package/dist/utilities/configToJSONSchema.js +103 -42
  84. package/dist/utilities/configToJSONSchema.js.map +1 -1
  85. package/dist/utilities/telemetry/conf/envPaths.d.ts +23 -0
  86. package/dist/utilities/telemetry/conf/envPaths.d.ts.map +1 -0
  87. package/dist/utilities/telemetry/conf/envPaths.js +70 -0
  88. package/dist/utilities/telemetry/conf/envPaths.js.map +1 -0
  89. package/dist/utilities/telemetry/conf/index.d.ts +84 -0
  90. package/dist/utilities/telemetry/conf/index.d.ts.map +1 -0
  91. package/dist/utilities/telemetry/conf/index.js +144 -0
  92. package/dist/utilities/telemetry/conf/index.js.map +1 -0
  93. package/dist/utilities/telemetry/index.d.ts.map +1 -1
  94. package/dist/utilities/telemetry/index.js +1 -1
  95. package/dist/utilities/telemetry/index.js.map +1 -1
  96. package/package.json +2 -3
  97. package/dist/auth/baseFields/loginField.d.ts +0 -4
  98. package/dist/auth/baseFields/loginField.d.ts.map +0 -1
  99. package/dist/auth/baseFields/loginField.js +0 -35
  100. package/dist/auth/baseFields/loginField.js.map +0 -1
@@ -97,6 +97,27 @@ function generateAuthEntitySchemas(entities) {
97
97
  oneOf: properties
98
98
  };
99
99
  }
100
+ /**
101
+ * Generates the JSON Schema for database configuration
102
+ *
103
+ * @example { db: idType: string }
104
+ */ function generateDbEntitySchema(config) {
105
+ const defaultIDType = config.db?.defaultIDType === 'number' ? {
106
+ type: 'number'
107
+ } : {
108
+ type: 'string'
109
+ };
110
+ return {
111
+ type: 'object',
112
+ additionalProperties: false,
113
+ properties: {
114
+ defaultIDType
115
+ },
116
+ required: [
117
+ 'defaultIDType'
118
+ ]
119
+ };
120
+ }
100
121
  /**
101
122
  * Returns a JSON Schema Type with 'null' added if the field is not required.
102
123
  */ export function withNullableJSONSchemaType(fieldType, isRequired) {
@@ -532,55 +553,93 @@ export function entityToJSONSchema(config, incomingEntity, interfaceNameDefiniti
532
553
  ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config)
533
554
  };
534
555
  }
535
- function generateOperationJSONSchema(config, operation) {
536
- const usernameLogin = config.auth?.loginWithUsername;
537
- const fieldType = {
538
- type: 'string'
556
+ const fieldType = {
557
+ type: 'string',
558
+ required: false
559
+ };
560
+ const generateAuthFieldTypes = (loginWithUsername, withPassword = false)=>{
561
+ const passwordField = {
562
+ password: fieldType
539
563
  };
540
- let properties = {};
541
- switch(operation){
542
- case 'login':
543
- {
544
- properties = {
545
- password: fieldType,
546
- [usernameLogin ? 'username' : 'email']: fieldType
547
- };
548
- break;
549
- }
550
- case 'forgotPassword':
551
- {
552
- properties = {
553
- [usernameLogin ? 'username' : 'email']: fieldType
554
- };
555
- break;
556
- }
557
- case 'registerFirstUser':
558
- {
559
- properties = {
560
- email: fieldType,
564
+ if (loginWithUsername) {
565
+ if (loginWithUsername.allowEmailLogin) {
566
+ return {
567
+ additionalProperties: false,
568
+ oneOf: [
569
+ {
570
+ additionalProperties: false,
571
+ properties: {
572
+ email: fieldType,
573
+ ...withPassword ? {
574
+ password: fieldType
575
+ } : {}
576
+ },
577
+ required: [
578
+ 'email',
579
+ ...withPassword ? [
580
+ 'password'
581
+ ] : []
582
+ ]
583
+ },
584
+ {
585
+ additionalProperties: false,
586
+ properties: {
587
+ username: fieldType,
588
+ ...withPassword ? {
589
+ password: fieldType
590
+ } : {}
591
+ },
592
+ required: [
593
+ 'username',
594
+ ...withPassword ? [
595
+ 'password'
596
+ ] : []
597
+ ]
598
+ }
599
+ ]
600
+ };
601
+ }
602
+ return {
603
+ additionalProperties: false,
604
+ properties: {
605
+ username: fieldType,
606
+ ...withPassword ? {
561
607
  password: fieldType
562
- };
563
- if (usernameLogin) properties.username = fieldType;
564
- break;
565
- }
608
+ } : {}
609
+ },
610
+ required: [
611
+ 'username',
612
+ ...withPassword ? [
613
+ 'password'
614
+ ] : []
615
+ ]
616
+ };
566
617
  }
567
618
  return {
568
619
  additionalProperties: false,
569
- properties,
570
- required: Object.keys(properties)
620
+ properties: {
621
+ email: fieldType,
622
+ ...withPassword ? {
623
+ password: fieldType
624
+ } : {}
625
+ },
626
+ required: [
627
+ 'email',
628
+ ...withPassword ? [
629
+ 'password'
630
+ ] : []
631
+ ]
571
632
  };
572
- }
633
+ };
573
634
  export function authCollectionToOperationsJSONSchema(config) {
635
+ const loginWithUsername = config.auth?.loginWithUsername;
636
+ const generatedFields = generateAuthFieldTypes(loginWithUsername);
637
+ const generatedFieldsWithPassword = generateAuthFieldTypes(loginWithUsername, true);
574
638
  const properties = {
575
- forgotPassword: {
576
- ...generateOperationJSONSchema(config, 'forgotPassword')
577
- },
578
- login: {
579
- ...generateOperationJSONSchema(config, 'login')
580
- },
581
- registerFirstUser: {
582
- ...generateOperationJSONSchema(config, 'registerFirstUser')
583
- }
639
+ forgotPassword: generatedFields,
640
+ login: generatedFieldsWithPassword,
641
+ registerFirstUser: generatedFieldsWithPassword,
642
+ unlock: generatedFields
584
643
  };
585
644
  return {
586
645
  type: 'object',
@@ -640,6 +699,7 @@ function generateAuthOperationSchemas(collections) {
640
699
  properties: {
641
700
  auth: generateAuthOperationSchemas(config.collections),
642
701
  collections: generateEntitySchemas(config.collections || []),
702
+ db: generateDbEntitySchema(config),
643
703
  globals: generateEntitySchemas(config.globals || []),
644
704
  locale: generateLocaleEntitySchemas(config.localization),
645
705
  user: generateAuthEntitySchemas(config.collections)
@@ -649,7 +709,8 @@ function generateAuthOperationSchemas(collections) {
649
709
  'locale',
650
710
  'collections',
651
711
  'globals',
652
- 'auth'
712
+ 'auth',
713
+ 'db'
653
714
  ],
654
715
  title: 'Config'
655
716
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FieldAffectingData, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { MissingEditorProp } from '../errors/MissingEditorProp.js'\nimport { fieldAffectsData, tabHasName } from '../fields/config/types.js'\nimport { deepCopyObject } from './deepCopyObject.js'\nimport { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: Field) => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) return false\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) return true\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.fields.some((subField) => fieldIsRequired(subField))\n }\n\n // if any tab subfields have required fields, this field is required\n if (field.type === 'tabs') {\n return field.tabs.some((tab) => {\n if ('name' in tab) {\n return tab.fields.some((subField) => fieldIsRequired(subField))\n }\n return false\n })\n }\n\n return false\n}\n\nfunction buildOptionEnums(options: Option[]): string[] {\n return options.map((option) => {\n if (typeof option === 'object' && 'value' in option) {\n return option.value\n }\n\n return option\n })\n}\n\nfunction generateEntitySchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateLocaleEntitySchemas(localization: SanitizedConfig['localization']): JSONSchema4 {\n if (localization && 'locales' in localization && localization?.locales) {\n const localesFromConfig = localization?.locales\n\n const locales = [...localesFromConfig].map((locale) => {\n return locale.code\n }, [])\n\n return {\n type: 'string',\n enum: locales,\n }\n }\n\n return {\n type: 'null',\n }\n}\n\nfunction generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties: JSONSchema4[] = [...entities]\n .filter(({ auth }) => Boolean(auth))\n .map(({ slug }) => {\n return {\n allOf: [\n { $ref: `#/definitions/${slug}` },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n collection: { type: 'string', enum: [slug] },\n },\n required: ['collection'],\n },\n ],\n }\n }, {})\n\n return {\n oneOf: properties,\n }\n}\n\n/**\n * Returns a JSON Schema Type with 'null' added if the field is not required.\n */\nexport function withNullableJSONSchemaType(\n fieldType: JSONSchema4TypeName,\n isRequired: boolean,\n): JSONSchema4TypeName | JSONSchema4TypeName[] {\n const fieldTypes = [fieldType]\n if (isRequired) return fieldType\n fieldTypes.push('null')\n return fieldTypes\n}\n\nexport function fieldsToJSONSchema(\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n fields: Field[],\n /**\n * Allows you to define new top-level interfaces that can be re-used in the output schema.\n */\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n config?: SanitizedConfig,\n): {\n properties: {\n [k: string]: JSONSchema4\n }\n required: string[]\n} {\n const requiredFieldNames = new Set<string>()\n\n return {\n properties: Object.fromEntries(\n fields.reduce((fieldSchemas, field) => {\n const isRequired = fieldAffectsData(field) && fieldIsRequired(field)\n if (isRequired) requiredFieldNames.add(field.name)\n\n let fieldSchema: JSONSchema4\n\n switch (field.type) {\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n }\n break\n case 'textarea':\n case 'code':\n case 'email':\n case 'date': {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('number', isRequired) }\n }\n break\n }\n\n case 'checkbox': {\n fieldSchema = { type: withNullableJSONSchemaType('boolean', isRequired) }\n break\n }\n\n case 'json': {\n fieldSchema = field.jsonSchema?.schema || {\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\n }\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n if (field.editor.outputSchema) {\n fieldSchema = field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n interfaceNameDefinitions,\n isRequired,\n })\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'radio': {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n enum: optionEnums,\n },\n }\n } else {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: optionEnums,\n }\n }\n\n break\n }\n\n case 'point': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'relationship': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n },\n }\n } else {\n fieldSchema = {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: withNullableJSONSchemaType('object', isRequired),\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n }\n }\n } else if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n },\n }\n } else {\n fieldSchema = {\n oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo],\n isRequired,\n ),\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n }\n\n break\n }\n\n case 'upload': {\n fieldSchema = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n if (!isRequired) fieldSchema.oneOf.push({ type: 'null' })\n break\n }\n\n case 'blocks': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.blocks.map((block) => {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.fields,\n interfaceNameDefinitions,\n config,\n )\n\n const blockSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...blockFieldSchemas.properties,\n blockType: {\n const: block.slug,\n },\n },\n required: ['blockType', ...blockFieldSchemas.required],\n }\n\n if (block.interfaceName) {\n interfaceNameDefinitions.set(block.interfaceName, blockSchema)\n\n return {\n $ref: `#/definitions/${block.interfaceName}`,\n }\n }\n\n return blockSchema\n }),\n },\n }\n break\n }\n\n case 'array': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n },\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n case 'row':\n case 'collapsible': {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n )\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n tab.fields,\n interfaceNameDefinitions,\n config,\n )\n if (tabHasName(tab)) {\n // could have interface\n fieldSchemas.set(tab.name, {\n type: 'object',\n additionalProperties: false,\n ...childSchema,\n })\n\n // If the named tab has any required fields then we mark this as required otherwise it should be optional\n const hasRequiredFields = tab.fields.some((subField) => fieldIsRequired(subField))\n\n if (hasRequiredFields) {\n requiredFieldNames.add(tab.name)\n }\n } else {\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n }\n })\n break\n }\n\n case 'group': {\n fieldSchema = {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if ('typescriptSchema' in field && field?.typescriptSchema?.length) {\n for (const schema of field.typescriptSchema) {\n fieldSchema = schema({ jsonSchema: fieldSchema })\n }\n }\n\n if (fieldSchema && fieldAffectsData(field)) {\n fieldSchemas.set(field.name, fieldSchema)\n }\n\n return fieldSchemas\n }, new Map<string, JSONSchema4>()),\n ),\n required: Array.from(requiredFieldNames),\n }\n}\n\n// This function is part of the public API and is exported through payload/utilities\nexport function entityToJSONSchema(\n config: SanitizedConfig,\n incomingEntity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n): JSONSchema4 {\n const entity: SanitizedCollectionConfig | SanitizedGlobalConfig = deepCopyObject(incomingEntity)\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = entity.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n customIdField.required = true\n } else {\n entity.fields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n entity.fields = entity.fields.map((field) => {\n if (fieldAffectsData(field) && (field.name === 'createdAt' || field.name === 'updatedAt')) {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if ('auth' in entity && entity.auth && !entity.auth?.disableLocalStrategy) {\n entity.fields.push({\n name: 'password',\n type: 'text',\n })\n }\n\n // Used for relationship fields, to determine whether to use a string or number type for the ID.\n const collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n\n return {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config),\n }\n}\n\nfunction generateOperationJSONSchema(\n config: SanitizedCollectionConfig,\n operation: 'forgotPassword' | 'login' | 'registerFirstUser',\n): JSONSchema4 {\n const usernameLogin = config.auth?.loginWithUsername\n const fieldType: JSONSchema4 = {\n type: 'string',\n }\n\n let properties: JSONSchema4['properties'] = {}\n switch (operation) {\n case 'login': {\n properties = {\n password: fieldType,\n [usernameLogin ? 'username' : 'email']: fieldType,\n }\n break\n }\n case 'forgotPassword': {\n properties = {\n [usernameLogin ? 'username' : 'email']: fieldType,\n }\n break\n }\n case 'registerFirstUser': {\n properties = {\n email: fieldType,\n password: fieldType,\n }\n if (usernameLogin) properties.username = fieldType\n break\n }\n }\n\n return {\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nexport function authCollectionToOperationsJSONSchema(\n config: SanitizedCollectionConfig,\n): JSONSchema4 {\n const properties = {\n forgotPassword: {\n ...generateOperationJSONSchema(config, 'forgotPassword'),\n },\n login: {\n ...generateOperationJSONSchema(config, 'login'),\n },\n registerFirstUser: {\n ...generateOperationJSONSchema(config, 'registerFirstUser'),\n },\n }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n title: `${singular(toWords(`${config.slug}`, true))}AuthOperations`,\n }\n}\n\nfunction generateAuthOperationSchemas(collections: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties = collections.reduce((acc, collection) => {\n if (collection.auth) {\n acc[collection.slug] = {\n $ref: `#/definitions/auth/${collection.slug}`,\n }\n }\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\n/**\n * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.\n */\nexport function configToJSONSchema(\n config: SanitizedConfig,\n defaultIDType?: 'number' | 'text',\n): JSONSchema4 {\n // a mutable Map to store custom top-level `interfaceName` types. Fields with an `interfaceName` property will be moved to the top-level definitions here\n const interfaceNameDefinitions: Map<string, JSONSchema4> = new Map()\n\n // Collections and Globals have to be moved to the top-level definitions as well. Reason: The top-level type will be the `Config` type - we don't want all collection and global\n // types to be inlined inside the `Config` type\n const entityDefinitions: { [k: string]: JSONSchema4 } = [\n ...config.globals,\n ...config.collections,\n ].reduce((acc, entity) => {\n acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType)\n return acc\n }, {})\n\n const authOperationDefinitions = [...config.collections]\n .filter(({ auth }) => Boolean(auth))\n .reduce(\n (acc, authCollection) => {\n acc.auth[authCollection.slug] = authCollectionToOperationsJSONSchema(authCollection)\n return acc\n },\n { auth: {} },\n )\n\n let jsonSchema: JSONSchema4 = {\n additionalProperties: false,\n definitions: {\n ...entityDefinitions,\n ...Object.fromEntries(interfaceNameDefinitions),\n ...authOperationDefinitions,\n },\n // These properties here will be very simple, as all the complexity is in the definitions. These are just the properties for the top-level `Config` type\n type: 'object',\n properties: {\n auth: generateAuthOperationSchemas(config.collections),\n collections: generateEntitySchemas(config.collections || []),\n globals: generateEntitySchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: ['user', 'locale', 'collections', 'globals', 'auth'],\n title: 'Config',\n }\n\n if (config?.typescript?.schema?.length) {\n for (const schema of config.typescript.schema) {\n jsonSchema = schema({ jsonSchema })\n }\n }\n\n return jsonSchema\n}\n"],"names":["pluralize","singular","MissingEditorProp","fieldAffectsData","tabHasName","deepCopyObject","toWords","getCollectionIDFieldTypes","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","fields","some","subField","tabs","tab","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","enum","generateAuthEntitySchemas","filter","auth","allOf","collection","oneOf","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","push","fieldsToJSONSchema","collectionIDFieldTypes","interfaceNameDefinitions","config","requiredFieldNames","Set","fromEntries","fieldSchemas","add","name","fieldSchema","hasMany","items","jsonSchema","schema","editor","Error","outputSchema","optionEnums","maxItems","minItems","Array","isArray","relationTo","relation","const","blocks","block","blockFieldSchemas","blockSchema","blockType","interfaceName","set","childSchema","entries","forEach","propName","propSchema","hasRequiredFields","typescriptSchema","length","Map","from","entityToJSONSchema","incomingEntity","defaultIDType","entity","title","typescript","interface","idField","customIdField","find","unshift","timestamps","disableLocalStrategy","generateOperationJSONSchema","operation","usernameLogin","loginWithUsername","password","email","username","authCollectionToOperationsJSONSchema","forgotPassword","login","registerFirstUser","generateAuthOperationSchemas","collections","configToJSONSchema","entityDefinitions","globals","authOperationDefinitions","authCollection","definitions","user"],"mappings":"AAEA,OAAOA,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AAOrB,SAASE,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,4BAA2B;AACxE,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,yBAAyB,QAAQ,iCAAgC;AAE1E,MAAMC,kBAAkB,CAACC;IACvB,MAAMC,gBAAgBC,QAAQF,OAAOG,SAASH,OAAOG,OAAOC;IAC5D,IAAIH,eAAe,OAAO;IAE1B,MAAMI,mBAAmB,cAAcL,SAASA,MAAMM,QAAQ,KAAK;IACnE,IAAIZ,iBAAiBM,UAAUK,kBAAkB,OAAO;IAExD,wDAAwD;IACxD,IAAI,YAAYL,SAASA,MAAMO,IAAI,KAAK,SAAS;QAC/C,OAAOP,MAAMQ,MAAM,CAACC,IAAI,CAAC,CAACC,WAAaX,gBAAgBW;IACzD;IAEA,oEAAoE;IACpE,IAAIV,MAAMO,IAAI,KAAK,QAAQ;QACzB,OAAOP,MAAMW,IAAI,CAACF,IAAI,CAAC,CAACG;YACtB,IAAI,U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C,QAAQ0B,QAAQ;QACtC,KAAK,MAAM1B,UAAUX,OAAO6C,UAAU,CAAClC,MAAM,CAAE;YAC7CD,aAAaC,OAAO;gBAAED;YAAW;QACnC;IACF;IAEA,OAAOA;AACT"}
1
+ {"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { Auth } from '../auth/types.js'\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FieldAffectingData, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { MissingEditorProp } from '../errors/MissingEditorProp.js'\nimport { fieldAffectsData, tabHasName } from '../fields/config/types.js'\nimport { deepCopyObject } from './deepCopyObject.js'\nimport { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: Field) => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) return false\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) return true\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.fields.some((subField) => fieldIsRequired(subField))\n }\n\n // if any tab subfields have required fields, this field is required\n if (field.type === 'tabs') {\n return field.tabs.some((tab) => {\n if ('name' in tab) {\n return tab.fields.some((subField) => fieldIsRequired(subField))\n }\n return false\n })\n }\n\n return false\n}\n\nfunction buildOptionEnums(options: Option[]): string[] {\n return options.map((option) => {\n if (typeof option === 'object' && 'value' in option) {\n return option.value\n }\n\n return option\n })\n}\n\nfunction generateEntitySchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateLocaleEntitySchemas(localization: SanitizedConfig['localization']): JSONSchema4 {\n if (localization && 'locales' in localization && localization?.locales) {\n const localesFromConfig = localization?.locales\n\n const locales = [...localesFromConfig].map((locale) => {\n return locale.code\n }, [])\n\n return {\n type: 'string',\n enum: locales,\n }\n }\n\n return {\n type: 'null',\n }\n}\n\nfunction generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties: JSONSchema4[] = [...entities]\n .filter(({ auth }) => Boolean(auth))\n .map(({ slug }) => {\n return {\n allOf: [\n { $ref: `#/definitions/${slug}` },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n collection: { type: 'string', enum: [slug] },\n },\n required: ['collection'],\n },\n ],\n }\n }, {})\n\n return {\n oneOf: properties,\n }\n}\n\n/**\n * Generates the JSON Schema for database configuration\n *\n * @example { db: idType: string }\n */\nfunction generateDbEntitySchema(config: SanitizedConfig): JSONSchema4 {\n const defaultIDType: JSONSchema4 =\n config.db?.defaultIDType === 'number' ? { type: 'number' } : { type: 'string' }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n defaultIDType,\n },\n required: ['defaultIDType'],\n }\n}\n\n/**\n * Returns a JSON Schema Type with 'null' added if the field is not required.\n */\nexport function withNullableJSONSchemaType(\n fieldType: JSONSchema4TypeName,\n isRequired: boolean,\n): JSONSchema4TypeName | JSONSchema4TypeName[] {\n const fieldTypes = [fieldType]\n if (isRequired) return fieldType\n fieldTypes.push('null')\n return fieldTypes\n}\n\nexport function fieldsToJSONSchema(\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n fields: Field[],\n /**\n * Allows you to define new top-level interfaces that can be re-used in the output schema.\n */\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n config?: SanitizedConfig,\n): {\n properties: {\n [k: string]: JSONSchema4\n }\n required: string[]\n} {\n const requiredFieldNames = new Set<string>()\n\n return {\n properties: Object.fromEntries(\n fields.reduce((fieldSchemas, field) => {\n const isRequired = fieldAffectsData(field) && fieldIsRequired(field)\n if (isRequired) requiredFieldNames.add(field.name)\n\n let fieldSchema: JSONSchema4\n\n switch (field.type) {\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n }\n break\n case 'textarea':\n case 'code':\n case 'email':\n case 'date': {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('number', isRequired) }\n }\n break\n }\n\n case 'checkbox': {\n fieldSchema = { type: withNullableJSONSchemaType('boolean', isRequired) }\n break\n }\n\n case 'json': {\n fieldSchema = field.jsonSchema?.schema || {\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\n }\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n if (field.editor.outputSchema) {\n fieldSchema = field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n interfaceNameDefinitions,\n isRequired,\n })\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'radio': {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n enum: optionEnums,\n },\n }\n } else {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: optionEnums,\n }\n }\n\n break\n }\n\n case 'point': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'relationship': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n },\n }\n } else {\n fieldSchema = {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: withNullableJSONSchemaType('object', isRequired),\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n }\n }\n } else if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n },\n }\n } else {\n fieldSchema = {\n oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo],\n isRequired,\n ),\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n }\n\n break\n }\n\n case 'upload': {\n fieldSchema = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n if (!isRequired) fieldSchema.oneOf.push({ type: 'null' })\n break\n }\n\n case 'blocks': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.blocks.map((block) => {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.fields,\n interfaceNameDefinitions,\n config,\n )\n\n const blockSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...blockFieldSchemas.properties,\n blockType: {\n const: block.slug,\n },\n },\n required: ['blockType', ...blockFieldSchemas.required],\n }\n\n if (block.interfaceName) {\n interfaceNameDefinitions.set(block.interfaceName, blockSchema)\n\n return {\n $ref: `#/definitions/${block.interfaceName}`,\n }\n }\n\n return blockSchema\n }),\n },\n }\n break\n }\n\n case 'array': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n },\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n case 'row':\n case 'collapsible': {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n )\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n tab.fields,\n interfaceNameDefinitions,\n config,\n )\n if (tabHasName(tab)) {\n // could have interface\n fieldSchemas.set(tab.name, {\n type: 'object',\n additionalProperties: false,\n ...childSchema,\n })\n\n // If the named tab has any required fields then we mark this as required otherwise it should be optional\n const hasRequiredFields = tab.fields.some((subField) => fieldIsRequired(subField))\n\n if (hasRequiredFields) {\n requiredFieldNames.add(tab.name)\n }\n } else {\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n }\n })\n break\n }\n\n case 'group': {\n fieldSchema = {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if ('typescriptSchema' in field && field?.typescriptSchema?.length) {\n for (const schema of field.typescriptSchema) {\n fieldSchema = schema({ jsonSchema: fieldSchema })\n }\n }\n\n if (fieldSchema && fieldAffectsData(field)) {\n fieldSchemas.set(field.name, fieldSchema)\n }\n\n return fieldSchemas\n }, new Map<string, JSONSchema4>()),\n ),\n required: Array.from(requiredFieldNames),\n }\n}\n\n// This function is part of the public API and is exported through payload/utilities\nexport function entityToJSONSchema(\n config: SanitizedConfig,\n incomingEntity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n): JSONSchema4 {\n const entity: SanitizedCollectionConfig | SanitizedGlobalConfig = deepCopyObject(incomingEntity)\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = entity.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n customIdField.required = true\n } else {\n entity.fields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n entity.fields = entity.fields.map((field) => {\n if (fieldAffectsData(field) && (field.name === 'createdAt' || field.name === 'updatedAt')) {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if ('auth' in entity && entity.auth && !entity.auth?.disableLocalStrategy) {\n entity.fields.push({\n name: 'password',\n type: 'text',\n })\n }\n\n // Used for relationship fields, to determine whether to use a string or number type for the ID.\n const collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n\n return {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config),\n }\n}\n\nconst fieldType: JSONSchema4 = {\n type: 'string',\n required: false,\n}\nconst generateAuthFieldTypes = (\n loginWithUsername: Auth['loginWithUsername'],\n withPassword = false,\n): JSONSchema4 => {\n const passwordField = {\n password: fieldType,\n }\n\n if (loginWithUsername) {\n if (loginWithUsername.allowEmailLogin) {\n return {\n additionalProperties: false,\n oneOf: [\n {\n additionalProperties: false,\n properties: { email: fieldType, ...(withPassword ? { password: fieldType } : {}) },\n required: ['email', ...(withPassword ? ['password'] : [])],\n },\n {\n additionalProperties: false,\n properties: { username: fieldType, ...(withPassword ? { password: fieldType } : {}) },\n required: ['username', ...(withPassword ? ['password'] : [])],\n },\n ],\n }\n }\n\n return {\n additionalProperties: false,\n properties: {\n username: fieldType,\n ...(withPassword ? { password: fieldType } : {}),\n },\n required: ['username', ...(withPassword ? ['password'] : [])],\n }\n }\n\n return {\n additionalProperties: false,\n properties: {\n email: fieldType,\n ...(withPassword ? { password: fieldType } : {}),\n },\n required: ['email', ...(withPassword ? ['password'] : [])],\n }\n}\n\nexport function authCollectionToOperationsJSONSchema(\n config: SanitizedCollectionConfig,\n): JSONSchema4 {\n const loginWithUsername = config.auth?.loginWithUsername\n const generatedFields: JSONSchema4 = generateAuthFieldTypes(loginWithUsername)\n const generatedFieldsWithPassword: JSONSchema4 = generateAuthFieldTypes(loginWithUsername, true)\n\n const properties: JSONSchema4['properties'] = {\n forgotPassword: generatedFields,\n login: generatedFieldsWithPassword,\n registerFirstUser: generatedFieldsWithPassword,\n unlock: generatedFields,\n }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n title: `${singular(toWords(`${config.slug}`, true))}AuthOperations`,\n }\n}\n\nfunction generateAuthOperationSchemas(collections: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties = collections.reduce((acc, collection) => {\n if (collection.auth) {\n acc[collection.slug] = {\n $ref: `#/definitions/auth/${collection.slug}`,\n }\n }\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\n/**\n * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.\n */\nexport function configToJSONSchema(\n config: SanitizedConfig,\n defaultIDType?: 'number' | 'text',\n): JSONSchema4 {\n // a mutable Map to store custom top-level `interfaceName` types. Fields with an `interfaceName` property will be moved to the top-level definitions here\n const interfaceNameDefinitions: Map<string, JSONSchema4> = new Map()\n\n // Collections and Globals have to be moved to the top-level definitions as well. Reason: The top-level type will be the `Config` type - we don't want all collection and global\n // types to be inlined inside the `Config` type\n const entityDefinitions: { [k: string]: JSONSchema4 } = [\n ...config.globals,\n ...config.collections,\n ].reduce((acc, entity) => {\n acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType)\n return acc\n }, {})\n\n const authOperationDefinitions = [...config.collections]\n .filter(({ auth }) => Boolean(auth))\n .reduce(\n (acc, authCollection) => {\n acc.auth[authCollection.slug] = authCollectionToOperationsJSONSchema(authCollection)\n return acc\n },\n { auth: {} },\n )\n\n let jsonSchema: JSONSchema4 = {\n additionalProperties: false,\n definitions: {\n ...entityDefinitions,\n ...Object.fromEntries(interfaceNameDefinitions),\n ...authOperationDefinitions,\n },\n // These properties here will be very simple, as all the complexity is in the definitions. These are just the properties for the top-level `Config` type\n type: 'object',\n properties: {\n auth: generateAuthOperationSchemas(config.collections),\n collections: generateEntitySchemas(config.collections || []),\n db: generateDbEntitySchema(config),\n globals: generateEntitySchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: ['user', 'locale', 'collections', 'globals', 'auth', 'db'],\n title: 'Config',\n }\n\n if (config?.typescript?.schema?.length) {\n for (const schema of config.typescript.schema) {\n jsonSchema = schema({ jsonSchema })\n }\n }\n\n return jsonSchema\n}\n"],"names":["pluralize","singular","MissingEditorProp","fieldAffectsData","tabHasName","deepCopyObject","toWords","getCollectionIDFieldTypes","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","fields","some","subField","tabs","tab","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","enum","generateAuthEntitySchemas","filter","auth","allOf","collection","oneOf","generateDbEntitySchema","config","defaultIDType","db","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","push","fieldsToJSONSchema","collectionIDFieldTypes","interfaceNameDefinitions","requiredFieldNames","Set","fromEntries","fieldSchemas","add","name","fieldSchema","hasMany","items","jsonSchema","schema","editor","Error","outputSchema","optionEnums","maxItems","minItems","Array","isArray","relationTo","relation","const","blocks","block","blockFieldSchemas","blockSchema","blockType","interfaceName","set","childSchema","entries","forEach","propName","propSchema","hasRequiredFields","typescriptSchema","length","Map","from","entityToJSONSchema","incomingEntity","entity","title","typescript","interface","idField","customIdField","find","unshift","timestamps","disableLocalStrategy","generateAuthFieldTypes","loginWithUsername","withPassword","passwordField","password","allowEmailLogin","email","username","authCollectionToOperationsJSONSchema","generatedFields","generatedFieldsWithPassword","forgotPassword","login","registerFirstUser","unlock","generateAuthOperationSchemas","collections","configToJSONSchema","entityDefinitions","globals","authOperationDefinitions","authCollection","definitions","user"],"mappings":"AAEA,OAAOA,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,E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IAAI,EAAE;YACnD3F,QAAQJ,4BAA4Bc,OAAOb,YAAY;YACvDkG,MAAM5F,0BAA0BO,OAAO8E,WAAW;QACpD;QACAlH,UAAU;YAAC;YAAQ;YAAU;YAAe;YAAW;YAAQ;SAAK;QACpEyF,OAAO;IACT;IAEA,IAAIrD,QAAQsD,YAAYjC,QAAQ0B,QAAQ;QACtC,KAAK,MAAM1B,UAAUrB,OAAOsD,UAAU,CAACjC,MAAM,CAAE;YAC7CD,aAAaC,OAAO;gBAAED;YAAW;QACnC;IACF;IAEA,OAAOA;AACT"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Taken from https://github.com/sindresorhus/env-paths/blob/main/index.js
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ *
12
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ */
14
+ export declare function envPaths(name: any, { suffix }?: {
15
+ suffix?: string;
16
+ }): {
17
+ cache: string;
18
+ config: string;
19
+ data: string;
20
+ log: string;
21
+ temp: string;
22
+ };
23
+ //# sourceMappingURL=envPaths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envPaths.d.ts","sourceRoot":"","sources":["../../../../src/utilities/telemetry/conf/envPaths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAkDH,wBAAgB,QAAQ,CAAC,IAAI,KAAA,EAAE,EAAE,MAAiB,EAAE;;CAAK;;;;;;EAmBxD"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Taken from https://github.com/sindresorhus/env-paths/blob/main/index.js
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ *
12
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ */ import os from 'node:os';
14
+ import path from 'node:path';
15
+ import process from 'node:process';
16
+ const homedir = os.homedir();
17
+ const tmpdir = os.tmpdir();
18
+ const { env } = process;
19
+ const macos = (name)=>{
20
+ const library = path.join(homedir, 'Library');
21
+ return {
22
+ cache: path.join(library, 'Caches', name),
23
+ config: path.join(library, 'Preferences', name),
24
+ data: path.join(library, 'Application Support', name),
25
+ log: path.join(library, 'Logs', name),
26
+ temp: path.join(tmpdir, name)
27
+ };
28
+ };
29
+ const windows = (name)=>{
30
+ const appData = env.APPDATA || path.join(homedir, 'AppData', 'Roaming');
31
+ const localAppData = env.LOCALAPPDATA || path.join(homedir, 'AppData', 'Local');
32
+ return {
33
+ // Data/config/cache/log are invented by me as Windows isn't opinionated about this
34
+ cache: path.join(localAppData, name, 'Cache'),
35
+ config: path.join(appData, name, 'Config'),
36
+ data: path.join(localAppData, name, 'Data'),
37
+ log: path.join(localAppData, name, 'Log'),
38
+ temp: path.join(tmpdir, name)
39
+ };
40
+ };
41
+ // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
42
+ const linux = (name)=>{
43
+ const username = path.basename(homedir);
44
+ return {
45
+ cache: path.join(env.XDG_CACHE_HOME || path.join(homedir, '.cache'), name),
46
+ config: path.join(env.XDG_CONFIG_HOME || path.join(homedir, '.config'), name),
47
+ data: path.join(env.XDG_DATA_HOME || path.join(homedir, '.local', 'share'), name),
48
+ // https://wiki.debian.org/XDGBaseDirectorySpecification#state
49
+ log: path.join(env.XDG_STATE_HOME || path.join(homedir, '.local', 'state'), name),
50
+ temp: path.join(tmpdir, username, name)
51
+ };
52
+ };
53
+ export function envPaths(name, { suffix = 'nodejs' } = {}) {
54
+ if (typeof name !== 'string') {
55
+ throw new TypeError(`Expected a string, got ${typeof name}`);
56
+ }
57
+ if (suffix) {
58
+ // Add suffix to prevent possible conflict with native apps
59
+ name += `-${suffix}`;
60
+ }
61
+ if (process.platform === 'darwin') {
62
+ return macos(name);
63
+ }
64
+ if (process.platform === 'win32') {
65
+ return windows(name);
66
+ }
67
+ return linux(name);
68
+ }
69
+
70
+ //# sourceMappingURL=envPaths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/utilities/telemetry/conf/envPaths.ts"],"sourcesContent":["/**\n * Taken from https://github.com/sindresorhus/env-paths/blob/main/index.js\n *\n * MIT License\n *\n * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\nimport os from 'node:os'\nimport path from 'node:path'\nimport process from 'node:process'\n\nconst homedir = os.homedir()\nconst tmpdir = os.tmpdir()\nconst { env } = process\n\nconst macos = (name) => {\n const library = path.join(homedir, 'Library')\n\n return {\n cache: path.join(library, 'Caches', name),\n config: path.join(library, 'Preferences', name),\n data: path.join(library, 'Application Support', name),\n log: path.join(library, 'Logs', name),\n temp: path.join(tmpdir, name),\n }\n}\n\nconst windows = (name) => {\n const appData = env.APPDATA || path.join(homedir, 'AppData', 'Roaming')\n const localAppData = env.LOCALAPPDATA || path.join(homedir, 'AppData', 'Local')\n\n return {\n // Data/config/cache/log are invented by me as Windows isn't opinionated about this\n cache: path.join(localAppData, name, 'Cache'),\n config: path.join(appData, name, 'Config'),\n data: path.join(localAppData, name, 'Data'),\n log: path.join(localAppData, name, 'Log'),\n temp: path.join(tmpdir, name),\n }\n}\n\n// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html\nconst linux = (name) => {\n const username = path.basename(homedir)\n\n return {\n cache: path.join(env.XDG_CACHE_HOME || path.join(homedir, '.cache'), name),\n config: path.join(env.XDG_CONFIG_HOME || path.join(homedir, '.config'), name),\n data: path.join(env.XDG_DATA_HOME || path.join(homedir, '.local', 'share'), name),\n // https://wiki.debian.org/XDGBaseDirectorySpecification#state\n log: path.join(env.XDG_STATE_HOME || path.join(homedir, '.local', 'state'), name),\n temp: path.join(tmpdir, username, name),\n }\n}\n\nexport function envPaths(name, { suffix = 'nodejs' } = {}) {\n if (typeof name !== 'string') {\n throw new TypeError(`Expected a string, got ${typeof name}`)\n }\n\n if (suffix) {\n // Add suffix to prevent possible conflict with native apps\n name += `-${suffix}`\n }\n\n if (process.platform === 'darwin') {\n return macos(name)\n }\n\n if (process.platform === 'win32') {\n return windows(name)\n }\n\n return linux(name)\n}\n"],"names":["os","path","process","homedir","tmpdir","env","macos","name","library","join","cache","config","data","log","temp","windows","appData","APPDATA","localAppData","LOCALAPPDATA","linux","username","basename","XDG_CACHE_HOME","XDG_CONFIG_HOME","XDG_DATA_HOME","XDG_STATE_HOME","envPaths","suffix","TypeError","platform"],"mappings":"AAAA;;;;;;;;;;;;CAYC,GAED,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAC5B,OAAOC,aAAa,eAAc;AAElC,MAAMC,UAAUH,GAAGG,OAAO;AAC1B,MAAMC,SAASJ,GAAGI,MAAM;AACxB,MAAM,EAAEC,GAAG,EAAE,GAAGH;AAEhB,MAAMI,QAAQ,CAACC;IACb,MAAMC,UAAUP,KAAKQ,IAAI,CAACN,SAAS;IAEnC,OAAO;QACLO,OAAOT,KAAKQ,IAAI,CAACD,SAAS,UAAUD;QACpCI,QAAQV,KAAKQ,IAAI,CAACD,SAAS,eAAeD;QAC1CK,MAAMX,KAAKQ,IAAI,CAACD,SAAS,uBAAuBD;QAChDM,KAAKZ,KAAKQ,IAAI,CAACD,SAAS,QAAQD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tB,KAAK,CAAC;IAC7D;IAEA,IAAIqB,QAAQ;QACV,2DAA2D;QAC3DrB,QAAQ,CAAC,CAAC,EAAEqB,OAAO,CAAC;IACtB;IAEA,IAAI1B,QAAQ4B,QAAQ,KAAK,UAAU;QACjC,OAAOxB,MAAMC;IACf;IAEA,IAAIL,QAAQ4B,QAAQ,KAAK,SAAS;QAChC,OAAOf,QAAQR;IACjB;IAEA,OAAOa,MAAMb;AACf"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Taken & simplified from https://github.com/sindresorhus/conf/blob/main/source/index.ts
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ *
12
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ */
14
+ export declare class Conf<T extends Record<string, any> = Record<string, unknown>> implements Iterable<[keyof T, T[keyof T]]> {
15
+ #private;
16
+ private readonly _deserialize;
17
+ private readonly _serialize;
18
+ readonly events: EventTarget;
19
+ readonly path: string;
20
+ constructor();
21
+ private _ensureDirectory;
22
+ private _write;
23
+ [Symbol.iterator](): IterableIterator<[keyof T, T[keyof T]]>;
24
+ /**
25
+ Delete an item.
26
+
27
+ @param key - The key of the item to delete.
28
+ */
29
+ delete(key: string): void;
30
+ /**
31
+ Get an item.
32
+
33
+ @param key - The key of the item to get.
34
+ */
35
+ get<Key extends keyof T>(key: Key): T[Key];
36
+ /**
37
+ Set an item or multiple items at once.
38
+
39
+ @param key - You can use [dot-notation](https://github.com/sindresorhus/dot-prop) in a key to access nested properties. Or a hashmap of items to set at once.
40
+ @param value - Must be JSON serializable. Trying to set the type `undefined`, `function`, or `symbol` will result in a `TypeError`.
41
+ */
42
+ set<Key extends keyof T>(key: string, value?: T[Key] | unknown): void;
43
+ get size(): number;
44
+ get store(): T;
45
+ set store(value: T);
46
+ }
47
+ export type Options = {
48
+ /**
49
+ The config is cleared if reading the config file causes a `SyntaxError`. This is a good behavior for unimportant data, as the config file is not intended to be hand-edited, so it usually means the config is corrupt and there's nothing the user can do about it anyway. However, if you let the user edit the config file directly, mistakes might happen and it could be more useful to throw an error when the config is invalid instead of clearing.
50
+
51
+ @default false
52
+ */
53
+ clearInvalidConfig?: boolean;
54
+ /**
55
+ The [mode](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) that will be used for the config file.
56
+
57
+ You would usually not need this, but it could be useful if you want to restrict the permissions of the config file. Setting a permission such as `0o600` would result in a config file that can only be accessed by the user running the program.
58
+
59
+ Note that setting restrictive permissions can cause problems if different users need to read the file. A common problem is a user running your tool with and without `sudo` and then not being able to access the config the second time.
60
+
61
+ @default 0o666
62
+ */
63
+ readonly configFileMode?: number;
64
+ /**
65
+ Name of the config file (without extension).
66
+
67
+ Useful if you need multiple config files for your app or module. For example, different config files between two major versions.
68
+
69
+ @default 'config'
70
+ */
71
+ configName?: string;
72
+ /**
73
+ Extension of the config file.
74
+
75
+ You would usually not need this, but could be useful if you want to interact with a file with a custom file extension that can be associated with your app. These might be simple save/export/preference files that are intended to be shareable or saved outside of the app.
76
+
77
+ @default 'json'
78
+ */
79
+ fileExtension?: string;
80
+ readonly projectSuffix?: string;
81
+ };
82
+ export type Serialize<T> = (value: T) => string;
83
+ export type Deserialize<T> = (text: string) => T;
84
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utilities/telemetry/conf/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAsBH,qBAAa,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACvE,YAAW,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;;IAG1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA+C;IAC5E,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkE;IAE7F,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;IAE5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;;IA6BrB,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,MAAM;IAMb,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAM7D;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAOzB;;;;OAIG;IACH,GAAG,CAAC,GAAG,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;IAK1C;;;;;OAKG;IACH,GAAG,CAAC,GAAG,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,GAAG,IAAI;IA6BrE,IAAI,IAAI,IAAI,MAAM,CAEjB;IACD,IAAI,KAAK,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