Skip to content

Commit

Permalink
feat(keystone): DOMA-10804 change field name
Browse files Browse the repository at this point in the history
  • Loading branch information
vovaaxeapolla committed Jan 23, 2025
1 parent 6bc3b06 commit a58a690
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 89 deletions.
4 changes: 2 additions & 2 deletions packages/keystone/KSv5v6/v5/registerSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const {
SignedDecimal,
Text,
EncryptedText,
CloudStorageText,
FileStorageText,
} = require('../../fields')
const { HiddenRelationship } = require('../../plugins/utils/HiddenRelationship')
const { AuthedRelationship, Relationship } = require('../../plugins/utils/Relationship')
Expand Down Expand Up @@ -86,7 +86,7 @@ function convertStringToTypes (schema) {
SignedDecimal,
Text,
EncryptedText,
CloudStorageText,
FileStorageText,
}
const allTypesForPrint = Object.keys(mapping).map(item => `"${item}"`).join(', ')

Expand Down
49 changes: 0 additions & 49 deletions packages/keystone/fields/CloudStorageText/README.md

This file was deleted.

7 changes: 0 additions & 7 deletions packages/keystone/fields/CloudStorageText/constants.js

This file was deleted.

14 changes: 0 additions & 14 deletions packages/keystone/fields/CloudStorageText/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Text } = require('@keystonejs/fields')

class CloudStorageTextImplementation extends Text.implementation {
class FileStorageTextImplementation extends Text.implementation {
constructor (path, {
adapter,
}) {
Expand Down Expand Up @@ -30,5 +30,5 @@ class CloudStorageTextImplementation extends Text.implementation {
}

module.exports = {
CloudStorageTextImplementation,
FileStorageTextImplementation,
}
64 changes: 64 additions & 0 deletions packages/keystone/fields/FileStorageText/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# FileStorageText

The `FileStorageText` field simplifies the storage of large text data by leveraging file storage solutions, reducing database load, and ensuring efficient handling of large datasets.

## Overview
The `FileStorageText` field is designed to store large text data in an external file storage system instead of directly in the database. This helps avoid database size limitations and improves overall system performance.

You can use this field in your code just like a standard `Text` field, but instead of storing the actual text in the database, only a reference (link) to the file is saved.

## Basic Usage

Add the `FileStorageText` field type to your schema along with a file adapter, and your text data will be stored in a file storage system. Below is an example:

```js
const fileAdapter = new FileAdapter('LOG_FILE_NAME')

keystone.createList('Log', {
fields: {
xmlLog: {
type: 'FileStorageText',
adapter: fileAdapter,
},
},
});
```

## GraphQL Behavior

The `FileStorageText` field behaves like a standard string (`Text` field) in GraphQL operations:

- **Create/Update:** The input value is saved to the configured file storage, and the database stores only a reference to the saved file.
- **Read:** The saved file is fetched from the file storage, and its contents are returned as a string.

However, the `FileStorageText` field does not support sorting, ordering, filtering, or searching in GraphQL.

## Storage

- **File Storage:** The actual text data is saved as a file in the configured file storage.
- **Database:** Only a reference (link) to the file in the file storage is saved in the database.

This approach keeps the database lightweight and optimized for operations.

## Configuration

You must configure a file adapter to use the `FileStorageText` field. Below are some examples:

```js
const fileAdapter = new FileAdapter('LOG_FILE_NAME')
```

or

```js
const fileAdapter = new FileAdapter('LOG_FILE_NAME', false, false, { bucket: 'BUCKET_FOR_LOGS'})
```

Make sure your file storage system is correctly configured and accessible.

## Notes

- The `FileStorageText` field is ideal for storing large logs, parsed data, or other text values that exceed typical database field size limits.
- Since the text is stored externally as a file, the database remains lean, and operations are more efficient.
- This field does not support sorting, ordering, filtering, or searching in GraphQL. It is designed solely for storing and retrieving large text values.
- Be sure to test your file storage setup to ensure data accessibility and integrity.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Text } = require('@keystonejs/fields')
const cuid = require('cuid')

const { CLOUD_STORAGE_TEXT_MIMETYPE, CLOUD_STORAGE_TEXT_ENCODING } = require('@open-condo/keystone/fields/CloudStorageText/constants')
const { FILE_STORAGE_TEXT_MIMETYPE, FILE_STORAGE_TEXT_ENCODING } = require('@open-condo/keystone/fields/FileStorageText/constants')
const { bufferToStream, readFileFromStream, getObjectStream } = require('@open-condo/keystone/file')


Expand All @@ -10,7 +10,7 @@ const CommonInterface = superclass => class extends superclass {
constructor () {
super(...arguments)
if (!this.config.adapter) {
throw new Error('CloudStorageText field cannot be used without a file adapter')
throw new Error('FileStorageText field cannot be used without a file adapter')
}
this.fileAdapter = this.config.adapter
}
Expand Down Expand Up @@ -38,17 +38,17 @@ const CommonInterface = superclass => class extends superclass {
const { id, filename, _meta } = await this.fileAdapter.save({
stream,
filename: originalFilename,
mimetype: CLOUD_STORAGE_TEXT_MIMETYPE,
encoding: CLOUD_STORAGE_TEXT_ENCODING,
mimetype: FILE_STORAGE_TEXT_MIMETYPE,
encoding: FILE_STORAGE_TEXT_ENCODING,
id: cuid(),
})

return {
id,
filename,
originalFilename,
mimetype: CLOUD_STORAGE_TEXT_MIMETYPE,
encoding: CLOUD_STORAGE_TEXT_ENCODING,
mimetype: FILE_STORAGE_TEXT_MIMETYPE,
encoding: FILE_STORAGE_TEXT_ENCODING,
_meta,
}
}
Expand All @@ -66,12 +66,12 @@ const CommonInterface = superclass => class extends superclass {
}
}

class CloudStorageTextKnexFieldAdapter extends CommonInterface(Text.adapters.knex) {}
class CloudStorageTextMongooseFieldAdapter extends CommonInterface(Text.adapters.mongoose) {}
class CloudStorageTextPrismaFieldAdapter extends CommonInterface(Text.adapters.prisma) {}
class FileStorageTextKnexFieldAdapter extends CommonInterface(Text.adapters.knex) {}
class FileStorageTextMongooseFieldAdapter extends CommonInterface(Text.adapters.mongoose) {}
class FileStorageTextPrismaFieldAdapter extends CommonInterface(Text.adapters.prisma) {}

module.exports = {
mongoose: CloudStorageTextKnexFieldAdapter,
knex: CloudStorageTextMongooseFieldAdapter,
prisma: CloudStorageTextPrismaFieldAdapter,
mongoose: FileStorageTextKnexFieldAdapter,
knex: FileStorageTextMongooseFieldAdapter,
prisma: FileStorageTextPrismaFieldAdapter,
}
7 changes: 7 additions & 0 deletions packages/keystone/fields/FileStorageText/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const FILE_STORAGE_TEXT_MIMETYPE = 'text/plain'
const FILE_STORAGE_TEXT_ENCODING = 'utf8'

module.exports = {
FILE_STORAGE_TEXT_MIMETYPE,
FILE_STORAGE_TEXT_ENCODING,
}
14 changes: 14 additions & 0 deletions packages/keystone/fields/FileStorageText/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { Text } = require('@keystonejs/fields')

const FileStorageTextAdapters = require('./adapters')
const { FileStorageTextImplementation } = require('./Implementation')

module.exports = {
type: 'FileStorageText',
implementation: FileStorageTextImplementation,
views: {
...Text.views,
Controller: require.resolve('./views/Controller'),
},
adapters: FileStorageTextAdapters,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FieldController from '@keystonejs/fields/Controller'

export default class CloudStorageTextController extends FieldController {
export default class FileStorageTextController extends FieldController {
getFilterTypes = () => []
}
4 changes: 2 additions & 2 deletions packages/keystone/fields/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const AddressPartWithType = require('./AddressPartWithType')
const AutoIncrementInteger = require('./AutoIncrementInteger')
const CloudStorageText = require('./CloudStorageText')
const DateInterval = require('./DateInterval')
const EncryptedText = require('./EncryptedText')
const FileStorageText = require('./FileStorageText')
const FileWithUTF8Name = require('./FileWithUTF8Name')
const Json = require('./Json')
const LocalizedText = require('./LocalizedText')
Expand All @@ -25,5 +25,5 @@ module.exports = {
FileWithUTF8Name,
Text,
EncryptedText,
CloudStorageText,
FileStorageText,
}

0 comments on commit a58a690

Please sign in to comment.