@getanthill/datastore
Advanced tools
Comparing version 0.80.3 to 0.81.0
@@ -63,3 +63,3 @@ "use strict"; | ||
res.header('Access-Control-Allow-Credentials', this.services.config.features.cors.allowCredentials); | ||
res.header('Access-Control-Allow-Headers', `${this.services.config.features.cors.allowHeaders},authorization,csrf-token,page,page-size,decrypt,content-type,cache-control`); | ||
res.header('Access-Control-Allow-Headers', `${this.services.config.features.cors.allowHeaders},authorization,csrf-token,page,page-size,decrypt,content-type,cache-control,cursor-last-id`); | ||
this.services.config.features.cors.allowMethods !== undefined && | ||
@@ -66,0 +66,0 @@ res.header('Access-Control-Allow-Methods', this.services.config.features.cors.allowMethods); |
@@ -70,9 +70,11 @@ "use strict"; | ||
const { type: eventType, v, json_patch: patch = [], ...fields } = event; | ||
if (state === null && | ||
eventType !== c.EVENT_TYPE_CREATED && | ||
eventSchema.is_created !== true) { | ||
const mustBeCreated = eventType !== c.EVENT_TYPE_CREATED && | ||
eventSchema.is_created !== true && | ||
eventSchema.upsert !== true; | ||
if (state === null && mustBeCreated === true) { | ||
throw new Error('Entity must be created first'); | ||
} | ||
if (state !== null && | ||
(eventType === c.EVENT_TYPE_CREATED || eventSchema.is_created === true)) { | ||
const mustNotBeCreated = eventType === c.EVENT_TYPE_CREATED || | ||
(eventSchema.upsert !== true && eventSchema.is_created === true); | ||
if (state !== null && mustNotBeCreated === true) { | ||
throw new Error('Entity already created'); | ||
@@ -79,0 +81,0 @@ } |
{ | ||
"name": "@getanthill/datastore", | ||
"description": "Event-Sourced Datastore", | ||
"version": "0.80.3", | ||
"version": "0.81.0", | ||
"main": "dist/sdk/index.js", | ||
@@ -6,0 +6,0 @@ "bin": { |
@@ -87,3 +87,3 @@ import type { Server } from 'http'; | ||
'Access-Control-Allow-Headers', | ||
`${this.services.config.features.cors.allowHeaders},authorization,csrf-token,page,page-size,decrypt,content-type,cache-control`, | ||
`${this.services.config.features.cors.allowHeaders},authorization,csrf-token,page,page-size,decrypt,content-type,cache-control,cursor-last-id`, | ||
); | ||
@@ -90,0 +90,0 @@ |
@@ -76,2 +76,3 @@ import crypto from 'crypto'; | ||
'0_0_0': { | ||
upsert: true, | ||
type: 'object', | ||
@@ -702,2 +703,48 @@ properties: { | ||
it('allows to apply arbitrary events without creation', async () => { | ||
const Users = GenericFactory(DEFAULT_DEFINITION, reducer, { | ||
CORRELATION_FIELD: 'user_id', | ||
SCHEMA: schemas, | ||
ORIGINAL_SCHEMA, | ||
MODEL_CONFIG, | ||
services, | ||
}); | ||
const user = new Users(services, setup.uuid()); | ||
await user.apply('AGE_UPDATED', { | ||
age: 12, | ||
type: 'AGE_UPDATED', | ||
}); | ||
expect(user.state).toMatchObject({ | ||
version: 0, | ||
age: 12, | ||
}); | ||
}); | ||
it('allows to apply multiply arbitrary events without creation', async () => { | ||
const Users = GenericFactory(DEFAULT_DEFINITION, reducer, { | ||
CORRELATION_FIELD: 'user_id', | ||
SCHEMA: schemas, | ||
ORIGINAL_SCHEMA, | ||
MODEL_CONFIG, | ||
services, | ||
}); | ||
const user = new Users(services); | ||
await user.create({ firstname: 'John', type: c.EVENT_TYPE_CREATED }); | ||
await user.apply('AGE_UPDATED', { | ||
age: 13, | ||
type: 'AGE_UPDATED', | ||
}); | ||
expect(user.state).toMatchObject({ | ||
version: 1, | ||
age: 13, | ||
}); | ||
}); | ||
describe('#archive / #unarchive / #delete', () => { | ||
@@ -704,0 +751,0 @@ let Users; |
@@ -77,14 +77,16 @@ import type { AnyObject, Event } from '../typings'; | ||
if ( | ||
state === null && | ||
const mustBeCreated = | ||
eventType !== c.EVENT_TYPE_CREATED && | ||
eventSchema.is_created !== true | ||
) { | ||
eventSchema.is_created !== true && | ||
eventSchema.upsert !== true; | ||
if (state === null && mustBeCreated === true) { | ||
throw new Error('Entity must be created first'); | ||
} | ||
if ( | ||
state !== null && | ||
(eventType === c.EVENT_TYPE_CREATED || eventSchema.is_created === true) | ||
) { | ||
const mustNotBeCreated = | ||
eventType === c.EVENT_TYPE_CREATED || | ||
(eventSchema.upsert !== true && eventSchema.is_created === true); | ||
if (state !== null && mustNotBeCreated === true) { | ||
throw new Error('Entity already created'); | ||
@@ -91,0 +93,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3171996
64879