Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

notabase

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

notabase - npm Package Compare versions

Comparing version 0.9.2 to 0.9.3

1

dist/collection.d.ts

@@ -19,2 +19,3 @@ import { Schema, IQueryCollection, CollectionValue } from './interface';

constructor(collectionId: any, collectionViewId: any, rawData: any, client: any);
updateSchemaProps(): void;
fetchMore(): Promise<void>;

@@ -21,0 +22,0 @@ addRow(data: any): any;

67

dist/collection.js

@@ -79,18 +79,38 @@ "use strict";

this.completed = false;
(function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(this.total > 980)) return [3 /*break*/, 2];
return [4 /*yield*/, this.fetchMore()];
case 1:
_a.sent();
_a.label = 2;
case 2:
this.completed = true;
return [2 /*return*/, this];
}
});
}); })();
// isFetchAll 默认打开,如果表格记录超过 980 条,会自动获取后面的数据。
if (this.client.isFetchAll) {
(function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(this.total > 980)) return [3 /*break*/, 2];
return [4 /*yield*/, this.fetchMore()];
case 1:
_a.sent();
_a.label = 2;
case 2:
this.completed = true;
return [2 /*return*/, this];
}
});
}); })();
}
else {
// isFetchAll 关闭的状态,表格记录超过 980 条, 控制台给出警告。后续的调用可能会有问题。
if (this.total > 980) {
console.warn("This table has more than 980 rows, but you set isFetchAll off. you can call collection.fetchMore() to get rest records");
}
}
}
Collection.prototype.updateSchemaProps = function () {
var _this = this;
this.props = Object.entries(this._schema).map(function (item) {
var key = item[0], v = item[1];
return v.name;
});
Object.entries(this._schema).map(function (item) {
var key = item[0], v = item[1];
_this.propsKeyMap[v.name] = __assign({ key: key }, v);
});
};
Collection.prototype.fetchMore = function () {

@@ -166,3 +186,3 @@ return __awaiter(this, void 0, void 0, function () {

}
this.client.reqeust.post('/api/v3/submitTransaction', postData);
this.client.submitTransaction(postData);
this.client.blockStore[newId] = {

@@ -468,3 +488,3 @@ value: {

};
_this.client.reqeust.post('/api/v3/submitTransaction', postData);
_this.client.submitTransaction(postData);
};

@@ -487,3 +507,3 @@ return del;

};
_this.client.reqeust.post('/api/v3/submitTransaction', postData);
_this.client.submitTransaction(postData);
_self = Reflect.set(target, prop, value);

@@ -512,3 +532,3 @@ return _self;

};
_this.client.reqeust.post('/api/v3/submitTransaction', postData);
_this.client.submitTransaction(postData);
return;

@@ -538,4 +558,6 @@ }

get: function (target, prop) {
var key = _this.propsKeyMap[prop].key;
return _this._schema[key];
var key = _this.propsKeyMap[prop] && _this.propsKeyMap[prop].key;
if (key)
return _this._schema[key];
return;
},

@@ -555,3 +577,4 @@ };

};
this.client.reqeust.post('/api/v3/submitTransaction', postData);
this.updateSchemaProps();
this.client.submitTransaction(postData);
};

@@ -558,0 +581,0 @@ return Collection;

@@ -11,2 +11,4 @@ import { Collection } from './collection';

export declare class Notabase {
isBatchUpdate: boolean;
isFetchAll: boolean;
utils: any;

@@ -26,4 +28,12 @@ blockStore: {

};
transactions: any[];
constructor(options?: NotabaseParams);
genId(): any;
submitTransaction(postData: any): Promise<void>;
startAtomic(): void;
endAtomic(): void;
/**
* isbBatchUpdate 为 true 时,正式提交修改
*/
submit(): Promise<void>;
searchBlocks(fullTableID: any, query: any): Promise<any>;

@@ -30,0 +40,0 @@ getBrowseableUrlByCollectionPageId(pageId: any): Promise<string>;

@@ -64,2 +64,4 @@ "use strict";

function Notabase(options) {
this.isBatchUpdate = false;
this.isFetchAll = true;
this.utils = utils;

@@ -69,2 +71,3 @@ this.blockStore = {};

this.collectionStore = {};
this.transactions = [];
// proxy > browser env + cloudflare worker

@@ -131,2 +134,42 @@ // token > node env

};
Notabase.prototype.submitTransaction = function (postData) {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
if (this.isBatchUpdate) {
// 25个提交为一个批次,超过 25个自动提交一次。
if (this.transactions.length > 100) {
this.submit();
}
(_a = this.transactions).push.apply(_a, postData.operations);
}
else {
this.reqeust.post('/api/v3/submitTransaction', postData);
}
return [2 /*return*/];
});
});
};
Notabase.prototype.startAtomic = function () {
this.isBatchUpdate = true;
};
Notabase.prototype.endAtomic = function () {
this.submit();
this.isBatchUpdate = false;
};
/**
* isbBatchUpdate 为 true 时,正式提交修改
*/
Notabase.prototype.submit = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.reqeust.post('/api/v3/submitTransaction', {
// requestId: this.genId(),
operations: this.transactions
});
this.transactions = [];
return [2 /*return*/];
});
});
};
Notabase.prototype.searchBlocks = function (fullTableID, query) {

@@ -133,0 +176,0 @@ return __awaiter(this, void 0, void 0, function () {

{
"name": "notabase",
"version": "0.9.2",
"version": "0.9.3",
"description": "API Wrapper For Notion's Database",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -47,11 +47,34 @@ import * as utils from './utils';

(async () => {
// isFetchAll 默认打开,如果表格记录超过 980 条,会自动获取后面的数据。
if (this.client.isFetchAll) {
(async () => {
if (this.total > 980) {
await this.fetchMore();
}
this.completed = true;
return this;
})()
} else {
// isFetchAll 关闭的状态,表格记录超过 980 条, 控制台给出警告。后续的调用可能会有问题。
if (this.total > 980) {
await this.fetchMore();
console.warn("This table has more than 980 rows, but you set isFetchAll off. you can call collection.fetchMore() to get rest records")
}
this.completed = true;
return this;
})()
}
}
updateSchemaProps() {
this.props = Object.entries(this._schema).map(item => {
let [key, v] = item
return v.name
})
Object.entries(this._schema).map(item => {
let [key, v] = item
this.propsKeyMap[v.name] = {
key,
...v
}
})
}
async fetchMore() {

@@ -116,3 +139,3 @@ const data = await this.client.queryCollection(this.collectionId, this.collectionViewId, this.total);

}
this.client.reqeust.post('/api/v3/submitTransaction', postData)
this.client.submitTransaction(postData)
this.client.blockStore[newId] = {

@@ -410,3 +433,3 @@ value: {

}
this.client.reqeust.post('/api/v3/submitTransaction', postData)
this.client.submitTransaction(postData)
}

@@ -428,3 +451,3 @@ return del

}
this.client.reqeust.post('/api/v3/submitTransaction', postData)
this.client.submitTransaction(postData)
_self = Reflect.set(target, prop, value)

@@ -452,3 +475,3 @@ return _self

}
this.client.reqeust.post('/api/v3/submitTransaction', postData)
this.client.submitTransaction(postData)
return

@@ -473,17 +496,6 @@ }

get: (target, prop) => {
let key = this.propsKeyMap[prop].key
return this._schema[key]
const key = this.propsKeyMap[prop] && this.propsKeyMap[prop].key
if (key) return this._schema[key]
return;
},
// set: (target, prop, value) => {
// let key = this.propsKeyMap[prop].key
// this._schema[key] = value
// let postData = {
// "operations": [
// { "id": this.collectionId, "table": "collection", "path": [], "command": "update", "args": { schema: this._schema } },
// ]
// }
// this.client.reqeust.post('/api/v3/submitTransaction', postData)
// return
// }
}

@@ -500,4 +512,5 @@ let proxy = new Proxy(this._schema, handlers)

}
this.client.reqeust.post('/api/v3/submitTransaction', postData)
this.updateSchemaProps()
this.client.submitTransaction(postData)
}
}

@@ -20,2 +20,4 @@ import { Collection } from './collection';

export class Notabase {
isBatchUpdate: boolean;
isFetchAll: boolean;
utils: any;

@@ -33,3 +35,7 @@ blockStore: {

}
transactions: any[];
constructor(options?: NotabaseParams) {
this.isBatchUpdate = false;
this.isFetchAll = true;
this.utils = utils

@@ -39,2 +45,3 @@ this.blockStore = {}

this.collectionStore = {}
this.transactions = []
// proxy > browser env + cloudflare worker

@@ -96,2 +103,33 @@ // token > node env

async submitTransaction(postData) {
if (this.isBatchUpdate) {
// 25个提交为一个批次,超过 25个自动提交一次。
if (this.transactions.length > 100) {
this.submit()
}
this.transactions.push(...postData.operations)
} else {
this.reqeust.post('/api/v3/submitTransaction', postData)
}
}
startAtomic() {
this.isBatchUpdate = true
}
endAtomic() {
this.submit()
this.isBatchUpdate = false
}
/**
* isbBatchUpdate 为 true 时,正式提交修改
*/
async submit() {
this.reqeust.post('/api/v3/submitTransaction', {
// requestId: this.genId(),
operations: this.transactions
})
this.transactions = []
}
async searchBlocks(fullTableID, query) {

@@ -98,0 +136,0 @@ let data = await this.reqeust.post(`/api/v3/searchBlocks`, {

@@ -1,2 +0,2 @@

const Notabase = require('../src/notabase')
const { Notabase } = require('../dist/notabase')

@@ -7,34 +7,34 @@ // node env

test('collection', async () => {
let testTable1Url = "https://www.notion.so/0a4155a50f6943e0bda2b6105cd41541?v=fe0a5e52a9ae4e1593e18307f98588a6"
let testTable2Url = "https://www.notion.so/20fc1b38973a452cbfd4944b10279d03?v=9de3852a009f4e0199c4d2c48b459131"
let testTable1Url = "https://www.notion.so/0a4155a50f6943e0bda2b6105cd41541?v=fe0a5e52a9ae4e1593e18307f98588a6"
let testTable2Url = "https://www.notion.so/20fc1b38973a452cbfd4944b10279d03?v=9de3852a009f4e0199c4d2c48b459131"
let db = await nb.fetchAll({
test1: testTable1Url,
test2: testTable2Url
})
let testTable1 = db.test1
// let testTable2 = db.test2
expect(testTable1.rows.length).toBeGreaterThanOrEqual(3);
let { Name, Text, Select, MultiSelect, Files, date, Person, Checkbox, Url, Email, Phone, Relation } = testTable1.rows[0]
let db = await nb.fetchAll({
test1: testTable1Url,
test2: testTable2Url
})
let testTable1 = db.test1
// let testTable2 = db.test2
expect(testTable1.rows.length).toBeGreaterThanOrEqual(3);
let { Name, Text, Select, MultiSelect, Files, date, Person, Checkbox, Url, Email, Phone, Relation } = testTable1.rows[0]
//String
expect(Name).toMatch('name')
expect(Text).toMatch('text')
expect(Select).toMatch('s1')
expect(Email).toMatch('test@gmail.com')
expect(Phone).toMatch('+8613812341234')
expect(Url).toMatch(/^https:\/\//)
//String
expect(Name).toMatch('name')
expect(Text).toMatch('text')
expect(Select).toMatch('s1')
expect(Email).toMatch('test@gmail.com')
expect(Phone).toMatch('+8613812341234')
expect(Url).toMatch(/^https:\/\//)
// Array
expect(MultiSelect).toContain('tag1')
expect(Files).toContain('https://s3-us-west-2.amazonaws.com/secure.notion-static.com/52fd8e51-0437-4082-ab5a-cf37edfc62de/hdImg_831f254ff0e73bacd6bc66ff0b665a5015447132841.jpg')
// Array
expect(MultiSelect).toContain('tag1')
expect(Files).toContain('https://s3-us-west-2.amazonaws.com/secure.notion-static.com/52fd8e51-0437-4082-ab5a-cf37edfc62de/hdImg_831f254ff0e73bacd6bc66ff0b665a5015447132841.jpg')
// Boolean
expect(Checkbox).toBe(true)
// Boolean
expect(Checkbox).toBe(true)
// advanced
expect(Person).toContain('62931804-ac73-4fb9-9a80-9075f7f0020a')
// fixme
// expect(date.startDate.toISOString()).toBe('2019-10-03T00:00:00.000Z')
expect(Relation[0].Name).toBe("table2 row1")
// advanced
expect(Person).toContain('62931804-ac73-4fb9-9a80-9075f7f0020a')
// fixme
// expect(date.startDate.toISOString()).toBe('2019-10-03T00:00:00.000Z')
expect(Relation[0].Name).toBe("table2 row1")

@@ -41,0 +41,0 @@ }, 10000)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc