@imbricate/core 3.0.3 → 3.1.0

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.
@@ -3,6 +3,8 @@
3
3
  * @namespace Database
4
4
  * @description Definition
5
5
  */
6
+ import { ImbricateAuthor } from "../author/definition";
7
+ import { ImbricateDatabaseSchema } from "./schema";
6
8
  /**
7
9
  * Query of the document
8
10
  *
@@ -13,3 +15,19 @@ export type ImbricateDocumentQuery = {
13
15
  readonly limit?: number;
14
16
  readonly skip?: number;
15
17
  };
18
+ /**
19
+ * Edit record type of the document
20
+ */
21
+ export declare enum IMBRICATE_DATABASE_EDIT_TYPE {
22
+ PUT_SCHEMA = "PUT_SCHEMA"
23
+ }
24
+ export type DatabaseEditOperation = {
25
+ readonly action: IMBRICATE_DATABASE_EDIT_TYPE;
26
+ readonly value: ImbricateDatabaseSchema;
27
+ };
28
+ export type DatabaseEditRecord = {
29
+ readonly uniqueIdentifier: string;
30
+ readonly editAt: Date;
31
+ readonly author: ImbricateAuthor;
32
+ readonly operations: DatabaseEditOperation[];
33
+ };
@@ -5,3 +5,11 @@
5
5
  * @description Definition
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.IMBRICATE_DATABASE_EDIT_TYPE = void 0;
9
+ /**
10
+ * Edit record type of the document
11
+ */
12
+ var IMBRICATE_DATABASE_EDIT_TYPE;
13
+ (function (IMBRICATE_DATABASE_EDIT_TYPE) {
14
+ IMBRICATE_DATABASE_EDIT_TYPE["PUT_SCHEMA"] = "PUT_SCHEMA";
15
+ })(IMBRICATE_DATABASE_EDIT_TYPE || (exports.IMBRICATE_DATABASE_EDIT_TYPE = IMBRICATE_DATABASE_EDIT_TYPE = {}));
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { IImbricateDocument } from "../document/interface";
7
7
  import { DocumentProperties } from "../document/property";
8
- import { ImbricateDocumentQuery } from "./definition";
8
+ import { DatabaseEditRecord, ImbricateDocumentQuery } from "./definition";
9
9
  import { ImbricateDatabaseSchema } from "./schema";
10
10
  export interface IImbricateDatabase {
11
11
  /**
@@ -20,6 +20,18 @@ export interface IImbricateDatabase {
20
20
  * Schema of the database
21
21
  */
22
22
  readonly schema: ImbricateDatabaseSchema;
23
+ /**
24
+ * Put and replace the schema of the database
25
+ * Existing documents will still be kept, and stays unchanged
26
+ *
27
+ * @param schema schema of the database
28
+ * @param noEditRecord do not add edit record, optional
29
+ *
30
+ * @returns a promise of the updated schema
31
+ * Note: if the origin supports Document Edit Record, the edit record will be added by default
32
+ * If you do not want to add the edit record, set `noEditRecord` to true
33
+ */
34
+ putSchema(schema: ImbricateDatabaseSchema, noEditRecord?: boolean): PromiseLike<void>;
23
35
  /**
24
36
  * Create a new document in the database
25
37
  * If origin supports Document Edit Record, the edit record will be added by default
@@ -47,4 +59,22 @@ export interface IImbricateDatabase {
47
59
  * @returns a promise of the documents in the database
48
60
  */
49
61
  queryDocuments(query: ImbricateDocumentQuery): PromiseLike<IImbricateDocument[]>;
62
+ /**
63
+ * Add edit records to the database, optional
64
+ * This method is optional, if not implemented, means the origin
65
+ * 1. The origin does not support edit records
66
+ * 2. The origin force to add edit records when put properties
67
+ *
68
+ * @param records database edit records
69
+ */
70
+ addEditRecords?(records: DatabaseEditRecord[]): PromiseLike<void>;
71
+ /**
72
+ * Get edit records of the database, optional
73
+ * This method is optional, if not implemented, means the origin
74
+ * 1. The origin does not support edit records
75
+ * 2. The origin force to add edit records when put properties
76
+ *
77
+ * @returns a promise of the edit records of the database
78
+ */
79
+ getEditRecords?(): PromiseLike<DatabaseEditRecord[]>;
50
80
  }
@@ -15,11 +15,17 @@ export declare enum IMBRICATE_PROPERTY_TYPE {
15
15
  }
16
16
  /**
17
17
  * Document properties
18
+ *
19
+ * Key - Property key, which should match schema properties unique identifier
20
+ * Value - Property value, which should match schema properties type
18
21
  */
19
22
  export type DocumentProperties = Record<DocumentPropertyKey, DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>>;
23
+ /**
24
+ * Document property key, which should match schema properties unique identifier
25
+ */
20
26
  export type DocumentPropertyKey = string;
21
27
  export type DocumentPropertyValue<T extends IMBRICATE_PROPERTY_TYPE> = {
22
- readonly type: IMBRICATE_PROPERTY_TYPE;
28
+ readonly type: T;
23
29
  readonly value: DocumentPropertyValueObject<T>;
24
30
  };
25
31
  export type DocumentPropertyValueObject<T extends IMBRICATE_PROPERTY_TYPE> = T extends IMBRICATE_PROPERTY_TYPE.STRING ? string : T extends IMBRICATE_PROPERTY_TYPE.MARKDOWN ? string : never;
@@ -23,7 +23,7 @@ const validateImbricateProperties = (properties, schema) => {
23
23
  const keys = Object.keys(properties);
24
24
  for (const key of keys) {
25
25
  const property = schema.properties.find((each) => {
26
- return each.propertyName === key;
26
+ return each.propertyIdentifier === key;
27
27
  });
28
28
  if (!property) {
29
29
  return `Property ${key} not found in schema`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imbricate/core",
3
3
  "main": "index.js",
4
- "version": "3.0.3",
4
+ "version": "3.1.0",
5
5
  "description": "Imbricate Core, Notebook for Engineers",
6
6
  "repository": {
7
7
  "type": "git",