Skip to content

Commit

Permalink
Merge branch 'alpha' into ci-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dplewis authored Aug 28, 2023
2 parents 35cf485 + c7b391d commit cb6f6df
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
7 changes: 7 additions & 0 deletions changelogs/CHANGELOG_alpha.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [4.2.0-alpha.6](https://github.com/parse-community/Parse-SDK-JS/compare/4.2.0-alpha.5...4.2.0-alpha.6) (2023-08-27)


### Features

* Add Bytes type to `Parse.Schema` ([#2001](https://github.com/parse-community/Parse-SDK-JS/issues/2001)) ([343d0d7](https://github.com/parse-community/Parse-SDK-JS/commit/343d0d729a57acdd3c9ba5c1dbe5738b3916ea04))

# [4.2.0-alpha.5](https://github.com/parse-community/Parse-SDK-JS/compare/4.2.0-alpha.4...4.2.0-alpha.5) (2023-08-27)


Expand Down
9 changes: 9 additions & 0 deletions integration/test/ParseSchemaTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('Schema', () => {
.addString('stringField')
.addNumber('numberField')
.addBoolean('booleanField')
.addBytes('bytesField')
.addDate('dateField')
.addFile('fileField')
.addGeoPoint('geoPointField')
Expand All @@ -91,6 +92,7 @@ describe('Schema', () => {
assert.equal(result.fields.stringField.type, 'String');
assert.equal(result.fields.numberField.type, 'Number');
assert.equal(result.fields.booleanField.type, 'Boolean');
assert.equal(result.fields.bytesField.type, 'Bytes');
assert.equal(result.fields.dateField.type, 'Date');
assert.equal(result.fields.fileField.type, 'File');
assert.equal(result.fields.geoPointField.type, 'GeoPoint');
Expand Down Expand Up @@ -182,6 +184,7 @@ describe('Schema', () => {
required: true,
defaultValue: '2000-01-01T00:00:00.000Z',
})
.addBytes('bytesField', { required: true, defaultValue: 'ParseA==' })
.addFile('fileField', { required: true, defaultValue: file })
.addGeoPoint('geoPointField', { required: true, defaultValue: point })
.addPolygon('polygonField', { required: true, defaultValue: polygon })
Expand All @@ -204,6 +207,11 @@ describe('Schema', () => {
stringField: { type: 'String', required: true, defaultValue: 'world' },
numberField: { type: 'Number', required: true, defaultValue: 10 },
booleanField: { type: 'Boolean', required: true, defaultValue: false },
bytesField: {
type: 'Bytes',
required: true,
defaultValue: { __type: 'Bytes', base64: 'ParseA==' },
},
dateField: {
type: 'Date',
required: true,
Expand Down Expand Up @@ -245,6 +253,7 @@ describe('Schema', () => {
stringField: 'world',
numberField: 10,
booleanField: false,
bytesField: { __type: 'Bytes', base64: 'ParseA==' },
dateField: { __type: 'Date', iso: '2000-01-01T00:00:00.000Z' },
dateStringField: { __type: 'Date', iso: '2000-01-01T00:00:00.000Z' },
fileField: file.toJSON(),
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parse",
"version": "4.2.0-alpha.5",
"version": "4.2.0-alpha.6",
"description": "Parse JavaScript SDK",
"homepage": "https://parseplatform.org",
"keywords": [
Expand Down
20 changes: 20 additions & 0 deletions src/ParseSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const FIELD_TYPES = [
'String',
'Number',
'Boolean',
'Bytes',
'Date',
'File',
'GeoPoint',
Expand Down Expand Up @@ -242,6 +243,14 @@ class ParseSchema {
};
}
}
if (type === 'Bytes') {
if (options && options.defaultValue) {
fieldOptions.defaultValue = {
__type: 'Bytes',
base64: options.defaultValue,
};
}
}
this._fields[name] = fieldOptions;
return this;
}
Expand Down Expand Up @@ -303,6 +312,17 @@ class ParseSchema {
return this.addField(name, 'Boolean', options);
}

/**
* Adding Bytes Field
*
* @param {string} name Name of the field that will be created on Parse
* @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
* @returns {Parse.Schema} Returns the schema, so you can chain this call.
*/
addBytes(name: string, options: FieldOptions) {
return this.addField(name, 'Bytes', options);
}

/**
* Adding Date Field
*
Expand Down
14 changes: 14 additions & 0 deletions src/__tests__/ParseSchema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('ParseSchema', () => {
.addString('stringField')
.addNumber('numberField')
.addBoolean('booleanField')
.addBytes('bytesField')
.addDate('dateField')
.addFile('fileField')
.addGeoPoint('geoPointField')
Expand All @@ -70,6 +71,7 @@ describe('ParseSchema', () => {
expect(schema._fields.stringField.type).toEqual('String');
expect(schema._fields.numberField.type).toEqual('Number');
expect(schema._fields.booleanField.type).toEqual('Boolean');
expect(schema._fields.bytesField.type).toEqual('Bytes');
expect(schema._fields.dateField.type).toEqual('Date');
expect(schema._fields.fileField.type).toEqual('File');
expect(schema._fields.geoPointField.type).toEqual('GeoPoint');
Expand Down Expand Up @@ -103,6 +105,10 @@ describe('ParseSchema', () => {
required: true,
defaultValue: 'hello',
})
.addBytes('bytesField', {
required: true,
defaultValue: 'ParseA==',
})
.addDate('dateField', {
required: true,
defaultValue: '2000-01-01T00:00:00.000Z',
Expand Down Expand Up @@ -131,6 +137,14 @@ describe('ParseSchema', () => {
iso: new Date('2000-01-01T00:00:00.000Z'),
},
});
expect(schema._fields.bytesField).toEqual({
type: 'Bytes',
required: true,
defaultValue: {
__type: 'Bytes',
base64: 'ParseA==',
},
});
});

it('can create schema indexes', done => {
Expand Down

0 comments on commit cb6f6df

Please sign in to comment.