@enonic/js-utils
Advanced tools
Comparing version 0.16.5 to 0.16.6
@@ -134,29 +134,80 @@ var __defProp = Object.defineProperty; | ||
// src/string/index.ts | ||
function lpad(u, w = 2, z = " ") { | ||
const s = "" + u; | ||
return s.length >= w ? s : new Array(w - s.length + 1).join(z) + s; | ||
} | ||
// src/mock/Branch.ts | ||
var DEFAULT_INDEX_CONFIG = { | ||
default: { | ||
decideByType: true, | ||
enabled: true, | ||
nGram: false, | ||
fulltext: false, | ||
includeInAllText: false, | ||
path: false, | ||
indexValueProcessors: [], | ||
languages: [] | ||
}, | ||
configs: [] | ||
}; | ||
var Branch = class { | ||
constructor() { | ||
this._nodes = {}; | ||
constructor({ | ||
repo | ||
}) { | ||
this._highest_id = 1; | ||
this._nodes = { | ||
"00000000-0000-0000-0000-000000000000": { | ||
_childOrder: "_ts DESC", | ||
_id: "00000000-0000-0000-0000-000000000000", | ||
_indexConfig: DEFAULT_INDEX_CONFIG, | ||
_inheritsPermissions: false, | ||
_name: "", | ||
_nodeType: "default", | ||
_path: "", | ||
_permissions: [{ | ||
principal: "role:system.admin", | ||
allow: [ | ||
"READ", | ||
"CREATE", | ||
"MODIFY", | ||
"DELETE", | ||
"PUBLISH", | ||
"READ_PERMISSIONS", | ||
"WRITE_PERMISSIONS" | ||
], | ||
deny: [] | ||
}], | ||
_state: "DEFAULT", | ||
_ts: Branch.generateInstantString(), | ||
_versionKey: "00000000-0000-4000-8000-000000000001" | ||
} | ||
}; | ||
this._repo = repo; | ||
this.log = this._repo.log; | ||
} | ||
static generateInstantString() { | ||
return new Date().toISOString(); | ||
} | ||
generateId() { | ||
this._highest_id += 1; | ||
return `00000000-0000-4000-8000-${lpad(this._highest_id, 11, "0")}`; | ||
} | ||
createNode(_a) { | ||
var _b = _a, { | ||
_id, | ||
_indexConfig = { | ||
default: { | ||
decideByType: false, | ||
enabled: true, | ||
nGram: false, | ||
fulltext: false, | ||
includeInAllText: false, | ||
path: false, | ||
indexValueProcessors: [], | ||
languages: [] | ||
}, | ||
configs: [] | ||
}, | ||
_name = _id | ||
_indexConfig = DEFAULT_INDEX_CONFIG, | ||
_name, | ||
_nodeType = "default" | ||
} = _b, rest = __objRest(_b, [ | ||
"_id", | ||
"_indexConfig", | ||
"_name" | ||
"_name", | ||
"_nodeType" | ||
]); | ||
const _id = this.generateId(); | ||
const _versionKey = this.generateId(); | ||
if (!_name) { | ||
_name = _id; | ||
} | ||
const _ts = Branch.generateInstantString(); | ||
if (this._nodes.hasOwnProperty(_id)) { | ||
@@ -168,3 +219,7 @@ throw new Error(`createNode: node with _id:${_id} already exist!`); | ||
_indexConfig, | ||
_name | ||
_name, | ||
_nodeType, | ||
_state: "DEFAULT", | ||
_ts, | ||
_versionKey | ||
}, enonify(rest)); | ||
@@ -189,3 +244,25 @@ this._nodes[_id] = node; | ||
} | ||
query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
}) { | ||
const ids = Object.keys(this._nodes); | ||
const total = ids.length; | ||
return { | ||
aggregations: {}, | ||
count: total, | ||
hits: ids.map((id) => ({ | ||
id, | ||
score: 1 | ||
})), | ||
total | ||
}; | ||
} | ||
}; | ||
module.exports = __toCommonJS(Branch_exports); |
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
var __objRest = (source, exclude) => { | ||
var target = {}; | ||
for (var prop in source) | ||
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) | ||
target[prop] = source[prop]; | ||
if (source != null && __getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(source)) { | ||
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) | ||
target[prop] = source[prop]; | ||
} | ||
return target; | ||
}; | ||
var __export = (target, all) => { | ||
@@ -57,15 +31,11 @@ for (var name in all) | ||
constructor({ | ||
branch | ||
branch, | ||
javaBridge | ||
}) { | ||
this._branch = branch; | ||
this._javaBridge = javaBridge; | ||
this.log = this._javaBridge.log; | ||
} | ||
create(_a) { | ||
var _b = _a, { | ||
_name | ||
} = _b, rest = __objRest(_b, [ | ||
"_name" | ||
]); | ||
return this._branch.createNode(__spreadValues({ | ||
_name | ||
}, rest)); | ||
create(param) { | ||
return this._branch.createNode(param); | ||
} | ||
@@ -84,3 +54,24 @@ get(...keys) { | ||
} | ||
query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
}) { | ||
return this._branch.query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
}); | ||
} | ||
}; | ||
module.exports = __toCommonJS(Connection_exports); |
@@ -59,15 +59,11 @@ var __defProp = Object.defineProperty; | ||
constructor({ | ||
branch | ||
branch, | ||
javaBridge | ||
}) { | ||
this._branch = branch; | ||
this._javaBridge = javaBridge; | ||
this.log = this._javaBridge.log; | ||
} | ||
create(_a) { | ||
var _b = _a, { | ||
_name | ||
} = _b, rest = __objRest(_b, [ | ||
"_name" | ||
]); | ||
return this._branch.createNode(__spreadValues({ | ||
_name | ||
}, rest)); | ||
create(param) { | ||
return this._branch.createNode(param); | ||
} | ||
@@ -86,2 +82,23 @@ get(...keys) { | ||
} | ||
query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
}) { | ||
return this._branch.query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
}); | ||
} | ||
}; | ||
@@ -167,29 +184,80 @@ | ||
// src/string/index.ts | ||
function lpad(u, w = 2, z = " ") { | ||
const s = "" + u; | ||
return s.length >= w ? s : new Array(w - s.length + 1).join(z) + s; | ||
} | ||
// src/mock/Branch.ts | ||
var DEFAULT_INDEX_CONFIG = { | ||
default: { | ||
decideByType: true, | ||
enabled: true, | ||
nGram: false, | ||
fulltext: false, | ||
includeInAllText: false, | ||
path: false, | ||
indexValueProcessors: [], | ||
languages: [] | ||
}, | ||
configs: [] | ||
}; | ||
var Branch = class { | ||
constructor() { | ||
this._nodes = {}; | ||
constructor({ | ||
repo | ||
}) { | ||
this._highest_id = 1; | ||
this._nodes = { | ||
"00000000-0000-0000-0000-000000000000": { | ||
_childOrder: "_ts DESC", | ||
_id: "00000000-0000-0000-0000-000000000000", | ||
_indexConfig: DEFAULT_INDEX_CONFIG, | ||
_inheritsPermissions: false, | ||
_name: "", | ||
_nodeType: "default", | ||
_path: "", | ||
_permissions: [{ | ||
principal: "role:system.admin", | ||
allow: [ | ||
"READ", | ||
"CREATE", | ||
"MODIFY", | ||
"DELETE", | ||
"PUBLISH", | ||
"READ_PERMISSIONS", | ||
"WRITE_PERMISSIONS" | ||
], | ||
deny: [] | ||
}], | ||
_state: "DEFAULT", | ||
_ts: Branch.generateInstantString(), | ||
_versionKey: "00000000-0000-4000-8000-000000000001" | ||
} | ||
}; | ||
this._repo = repo; | ||
this.log = this._repo.log; | ||
} | ||
static generateInstantString() { | ||
return new Date().toISOString(); | ||
} | ||
generateId() { | ||
this._highest_id += 1; | ||
return `00000000-0000-4000-8000-${lpad(this._highest_id, 11, "0")}`; | ||
} | ||
createNode(_a) { | ||
var _b = _a, { | ||
_id, | ||
_indexConfig = { | ||
default: { | ||
decideByType: false, | ||
enabled: true, | ||
nGram: false, | ||
fulltext: false, | ||
includeInAllText: false, | ||
path: false, | ||
indexValueProcessors: [], | ||
languages: [] | ||
}, | ||
configs: [] | ||
}, | ||
_name = _id | ||
_indexConfig = DEFAULT_INDEX_CONFIG, | ||
_name, | ||
_nodeType = "default" | ||
} = _b, rest = __objRest(_b, [ | ||
"_id", | ||
"_indexConfig", | ||
"_name" | ||
"_name", | ||
"_nodeType" | ||
]); | ||
const _id = this.generateId(); | ||
const _versionKey = this.generateId(); | ||
if (!_name) { | ||
_name = _id; | ||
} | ||
const _ts = Branch.generateInstantString(); | ||
if (this._nodes.hasOwnProperty(_id)) { | ||
@@ -201,3 +269,7 @@ throw new Error(`createNode: node with _id:${_id} already exist!`); | ||
_indexConfig, | ||
_name | ||
_name, | ||
_nodeType, | ||
_state: "DEFAULT", | ||
_ts, | ||
_versionKey | ||
}, enonify(rest)); | ||
@@ -222,2 +294,24 @@ this._nodes[_id] = node; | ||
} | ||
query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
}) { | ||
const ids = Object.keys(this._nodes); | ||
const total = ids.length; | ||
return { | ||
aggregations: {}, | ||
count: total, | ||
hits: ids.map((id) => ({ | ||
id, | ||
score: 1 | ||
})), | ||
total | ||
}; | ||
} | ||
}; | ||
@@ -229,9 +323,14 @@ | ||
id, | ||
javaBridge, | ||
settings = {} | ||
}) { | ||
this._id = id; | ||
this._javaBridge = javaBridge; | ||
this.log = this._javaBridge.log; | ||
this._settings = settings; | ||
this._branches = { | ||
"master": new Branch() | ||
"master": new Branch({ | ||
repo: this | ||
}) | ||
}; | ||
this._id = id; | ||
this._settings = settings; | ||
} | ||
@@ -282,2 +381,3 @@ get() { | ||
id, | ||
javaBridge: this, | ||
settings | ||
@@ -322,3 +422,6 @@ }); | ||
const branchObj = repo.getBranch(branch); | ||
const connection = new Connection({ branch: branchObj }); | ||
const connection = new Connection({ | ||
branch: branchObj, | ||
javaBridge: this | ||
}); | ||
return connection; | ||
@@ -325,0 +428,0 @@ } |
@@ -59,15 +59,11 @@ var __defProp = Object.defineProperty; | ||
constructor({ | ||
branch | ||
branch, | ||
javaBridge | ||
}) { | ||
this._branch = branch; | ||
this._javaBridge = javaBridge; | ||
this.log = this._javaBridge.log; | ||
} | ||
create(_a) { | ||
var _b = _a, { | ||
_name | ||
} = _b, rest = __objRest(_b, [ | ||
"_name" | ||
]); | ||
return this._branch.createNode(__spreadValues({ | ||
_name | ||
}, rest)); | ||
create(param) { | ||
return this._branch.createNode(param); | ||
} | ||
@@ -86,2 +82,23 @@ get(...keys) { | ||
} | ||
query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
}) { | ||
return this._branch.query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
}); | ||
} | ||
}; | ||
@@ -167,29 +184,80 @@ | ||
// src/string/index.ts | ||
function lpad(u, w = 2, z = " ") { | ||
const s = "" + u; | ||
return s.length >= w ? s : new Array(w - s.length + 1).join(z) + s; | ||
} | ||
// src/mock/Branch.ts | ||
var DEFAULT_INDEX_CONFIG = { | ||
default: { | ||
decideByType: true, | ||
enabled: true, | ||
nGram: false, | ||
fulltext: false, | ||
includeInAllText: false, | ||
path: false, | ||
indexValueProcessors: [], | ||
languages: [] | ||
}, | ||
configs: [] | ||
}; | ||
var Branch = class { | ||
constructor() { | ||
this._nodes = {}; | ||
constructor({ | ||
repo | ||
}) { | ||
this._highest_id = 1; | ||
this._nodes = { | ||
"00000000-0000-0000-0000-000000000000": { | ||
_childOrder: "_ts DESC", | ||
_id: "00000000-0000-0000-0000-000000000000", | ||
_indexConfig: DEFAULT_INDEX_CONFIG, | ||
_inheritsPermissions: false, | ||
_name: "", | ||
_nodeType: "default", | ||
_path: "", | ||
_permissions: [{ | ||
principal: "role:system.admin", | ||
allow: [ | ||
"READ", | ||
"CREATE", | ||
"MODIFY", | ||
"DELETE", | ||
"PUBLISH", | ||
"READ_PERMISSIONS", | ||
"WRITE_PERMISSIONS" | ||
], | ||
deny: [] | ||
}], | ||
_state: "DEFAULT", | ||
_ts: Branch.generateInstantString(), | ||
_versionKey: "00000000-0000-4000-8000-000000000001" | ||
} | ||
}; | ||
this._repo = repo; | ||
this.log = this._repo.log; | ||
} | ||
static generateInstantString() { | ||
return new Date().toISOString(); | ||
} | ||
generateId() { | ||
this._highest_id += 1; | ||
return `00000000-0000-4000-8000-${lpad(this._highest_id, 11, "0")}`; | ||
} | ||
createNode(_a) { | ||
var _b = _a, { | ||
_id, | ||
_indexConfig = { | ||
default: { | ||
decideByType: false, | ||
enabled: true, | ||
nGram: false, | ||
fulltext: false, | ||
includeInAllText: false, | ||
path: false, | ||
indexValueProcessors: [], | ||
languages: [] | ||
}, | ||
configs: [] | ||
}, | ||
_name = _id | ||
_indexConfig = DEFAULT_INDEX_CONFIG, | ||
_name, | ||
_nodeType = "default" | ||
} = _b, rest = __objRest(_b, [ | ||
"_id", | ||
"_indexConfig", | ||
"_name" | ||
"_name", | ||
"_nodeType" | ||
]); | ||
const _id = this.generateId(); | ||
const _versionKey = this.generateId(); | ||
if (!_name) { | ||
_name = _id; | ||
} | ||
const _ts = Branch.generateInstantString(); | ||
if (this._nodes.hasOwnProperty(_id)) { | ||
@@ -201,3 +269,7 @@ throw new Error(`createNode: node with _id:${_id} already exist!`); | ||
_indexConfig, | ||
_name | ||
_name, | ||
_nodeType, | ||
_state: "DEFAULT", | ||
_ts, | ||
_versionKey | ||
}, enonify(rest)); | ||
@@ -222,2 +294,24 @@ this._nodes[_id] = node; | ||
} | ||
query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
}) { | ||
const ids = Object.keys(this._nodes); | ||
const total = ids.length; | ||
return { | ||
aggregations: {}, | ||
count: total, | ||
hits: ids.map((id) => ({ | ||
id, | ||
score: 1 | ||
})), | ||
total | ||
}; | ||
} | ||
}; | ||
@@ -229,9 +323,14 @@ | ||
id, | ||
javaBridge, | ||
settings = {} | ||
}) { | ||
this._id = id; | ||
this._javaBridge = javaBridge; | ||
this.log = this._javaBridge.log; | ||
this._settings = settings; | ||
this._branches = { | ||
"master": new Branch() | ||
"master": new Branch({ | ||
repo: this | ||
}) | ||
}; | ||
this._id = id; | ||
this._settings = settings; | ||
} | ||
@@ -282,2 +381,3 @@ get() { | ||
id, | ||
javaBridge: this, | ||
settings | ||
@@ -322,3 +422,6 @@ }); | ||
const branchObj = repo.getBranch(branch); | ||
const connection = new Connection({ branch: branchObj }); | ||
const connection = new Connection({ | ||
branch: branchObj, | ||
javaBridge: this | ||
}); | ||
return connection; | ||
@@ -325,0 +428,0 @@ } |
@@ -134,29 +134,80 @@ var __defProp = Object.defineProperty; | ||
// src/string/index.ts | ||
function lpad(u, w = 2, z = " ") { | ||
const s = "" + u; | ||
return s.length >= w ? s : new Array(w - s.length + 1).join(z) + s; | ||
} | ||
// src/mock/Branch.ts | ||
var DEFAULT_INDEX_CONFIG = { | ||
default: { | ||
decideByType: true, | ||
enabled: true, | ||
nGram: false, | ||
fulltext: false, | ||
includeInAllText: false, | ||
path: false, | ||
indexValueProcessors: [], | ||
languages: [] | ||
}, | ||
configs: [] | ||
}; | ||
var Branch = class { | ||
constructor() { | ||
this._nodes = {}; | ||
constructor({ | ||
repo | ||
}) { | ||
this._highest_id = 1; | ||
this._nodes = { | ||
"00000000-0000-0000-0000-000000000000": { | ||
_childOrder: "_ts DESC", | ||
_id: "00000000-0000-0000-0000-000000000000", | ||
_indexConfig: DEFAULT_INDEX_CONFIG, | ||
_inheritsPermissions: false, | ||
_name: "", | ||
_nodeType: "default", | ||
_path: "", | ||
_permissions: [{ | ||
principal: "role:system.admin", | ||
allow: [ | ||
"READ", | ||
"CREATE", | ||
"MODIFY", | ||
"DELETE", | ||
"PUBLISH", | ||
"READ_PERMISSIONS", | ||
"WRITE_PERMISSIONS" | ||
], | ||
deny: [] | ||
}], | ||
_state: "DEFAULT", | ||
_ts: Branch.generateInstantString(), | ||
_versionKey: "00000000-0000-4000-8000-000000000001" | ||
} | ||
}; | ||
this._repo = repo; | ||
this.log = this._repo.log; | ||
} | ||
static generateInstantString() { | ||
return new Date().toISOString(); | ||
} | ||
generateId() { | ||
this._highest_id += 1; | ||
return `00000000-0000-4000-8000-${lpad(this._highest_id, 11, "0")}`; | ||
} | ||
createNode(_a) { | ||
var _b = _a, { | ||
_id, | ||
_indexConfig = { | ||
default: { | ||
decideByType: false, | ||
enabled: true, | ||
nGram: false, | ||
fulltext: false, | ||
includeInAllText: false, | ||
path: false, | ||
indexValueProcessors: [], | ||
languages: [] | ||
}, | ||
configs: [] | ||
}, | ||
_name = _id | ||
_indexConfig = DEFAULT_INDEX_CONFIG, | ||
_name, | ||
_nodeType = "default" | ||
} = _b, rest = __objRest(_b, [ | ||
"_id", | ||
"_indexConfig", | ||
"_name" | ||
"_name", | ||
"_nodeType" | ||
]); | ||
const _id = this.generateId(); | ||
const _versionKey = this.generateId(); | ||
if (!_name) { | ||
_name = _id; | ||
} | ||
const _ts = Branch.generateInstantString(); | ||
if (this._nodes.hasOwnProperty(_id)) { | ||
@@ -168,3 +219,7 @@ throw new Error(`createNode: node with _id:${_id} already exist!`); | ||
_indexConfig, | ||
_name | ||
_name, | ||
_nodeType, | ||
_state: "DEFAULT", | ||
_ts, | ||
_versionKey | ||
}, enonify(rest)); | ||
@@ -189,2 +244,24 @@ this._nodes[_id] = node; | ||
} | ||
query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
}) { | ||
const ids = Object.keys(this._nodes); | ||
const total = ids.length; | ||
return { | ||
aggregations: {}, | ||
count: total, | ||
hits: ids.map((id) => ({ | ||
id, | ||
score: 1 | ||
})), | ||
total | ||
}; | ||
} | ||
}; | ||
@@ -196,9 +273,14 @@ | ||
id, | ||
javaBridge, | ||
settings = {} | ||
}) { | ||
this._id = id; | ||
this._javaBridge = javaBridge; | ||
this.log = this._javaBridge.log; | ||
this._settings = settings; | ||
this._branches = { | ||
"master": new Branch() | ||
"master": new Branch({ | ||
repo: this | ||
}) | ||
}; | ||
this._id = id; | ||
this._settings = settings; | ||
} | ||
@@ -205,0 +287,0 @@ get() { |
@@ -57,3 +57,3 @@ { | ||
}, | ||
"version": "0.16.5" | ||
"version": "0.16.6" | ||
} |
@@ -1,10 +0,13 @@ | ||
import type { | ||
MockNode, | ||
MockNodeCreateParam, | ||
MockNodeModifyParam | ||
} from './node.d'; | ||
import type { Log } from './globals.d' | ||
import type { RepoNodeWithData } from './node/node.d'; | ||
import type { NodeCreateParams } from './node/create.d'; | ||
import type { NodeModifyParams } from './node/modify.d'; | ||
import type { NodeQueryParams } from './node/query'; | ||
import type { NodeQueryResponse } from './node/repoConnection.d'; | ||
import type { Repo } from './Repo'; | ||
import { | ||
enonify, | ||
flatten | ||
flatten, | ||
lpad | ||
} from '../'; | ||
@@ -14,43 +17,106 @@ | ||
interface Nodes { | ||
[key :string] :MockNode | ||
[key :string] :RepoNodeWithData | ||
} | ||
const DEFAULT_INDEX_CONFIG = { | ||
default: { | ||
decideByType: true, | ||
enabled: true, | ||
nGram: false, | ||
fulltext: false, | ||
includeInAllText: false, | ||
path: false, | ||
indexValueProcessors: [], | ||
languages: [] | ||
}, | ||
configs: [] | ||
}; | ||
export class Branch { | ||
private _nodes :Nodes = {}; | ||
static generateInstantString() { | ||
return new Date().toISOString(); | ||
} | ||
constructor() {} | ||
private _highest_id :number = 1; | ||
private _nodes :Nodes = { | ||
'00000000-0000-0000-0000-000000000000': { | ||
_childOrder: '_ts DESC', | ||
_id: '00000000-0000-0000-0000-000000000000', | ||
_indexConfig: DEFAULT_INDEX_CONFIG, | ||
_inheritsPermissions: false, | ||
_name: '', | ||
_nodeType: 'default', | ||
_path: '', | ||
_permissions: [{ | ||
principal: 'role:system.admin', | ||
allow: [ | ||
'READ', | ||
'CREATE', | ||
'MODIFY', | ||
'DELETE', | ||
'PUBLISH', | ||
'READ_PERMISSIONS', | ||
'WRITE_PERMISSIONS' | ||
], | ||
deny: [] | ||
}], | ||
_state: 'DEFAULT', | ||
_ts: Branch.generateInstantString(), | ||
_versionKey: '00000000-0000-4000-8000-000000000001' | ||
} | ||
}; | ||
private _repo :Repo; | ||
readonly log :Log; | ||
constructor({ | ||
repo | ||
} :{ | ||
repo :Repo | ||
}) { | ||
//console.debug('repo.constructor.name',repo.constructor.name); | ||
this._repo = repo; | ||
this.log = this._repo.log; | ||
//this.log.debug('in Branch constructor'); | ||
} | ||
private generateId() :string { | ||
this._highest_id += 1; | ||
return `00000000-0000-4000-8000-${lpad(this._highest_id,11,'0')}`; | ||
} | ||
createNode({ | ||
//_childOrder, | ||
_id, // Not possible in Enonic XP, useful here for testing | ||
_indexConfig = { | ||
default: { | ||
decideByType: false, | ||
enabled: true, | ||
nGram: false, | ||
fulltext: false, | ||
includeInAllText: false, | ||
path: false, | ||
indexValueProcessors: [], | ||
languages: [] | ||
}, | ||
configs: [] | ||
}, | ||
//_id, // avoid it ending up in rest | ||
_indexConfig = DEFAULT_INDEX_CONFIG, | ||
//_inheritsPermissions, | ||
//_manualOrderValue, | ||
_name = _id, | ||
_name, | ||
_nodeType = 'default', | ||
//_parentPath, | ||
//_permissions, | ||
//_state, // avoid it ending up in rest | ||
//_ts, // avoid it ending up in rest | ||
//_versionKey, // avoid it ending up in rest | ||
...rest | ||
} :MockNodeCreateParam) :MockNode { | ||
} :NodeCreateParams) :RepoNodeWithData { | ||
//if (rest.hasOwnProperty('_id')) { delete rest._id; } | ||
//if (rest.hasOwnProperty('_versionKey')) { delete rest._versionKey; } | ||
const _id = this.generateId(); | ||
const _versionKey = this.generateId(); | ||
if (!_name) { _name = _id; } | ||
const _ts = Branch.generateInstantString(); | ||
if (this._nodes.hasOwnProperty(_id as string)) { | ||
throw new Error(`createNode: node with _id:${_id} already exist!`); | ||
} | ||
const node :MockNode = { | ||
const node :RepoNodeWithData = { | ||
_id, | ||
_indexConfig, | ||
_name, | ||
_nodeType, | ||
_state: 'DEFAULT', | ||
_ts, | ||
_versionKey, | ||
...(enonify(rest) as Object) | ||
} as MockNode; | ||
} as RepoNodeWithData; | ||
this._nodes[_id] = node; | ||
@@ -60,3 +126,3 @@ return node; | ||
getNode(...keys :string[]) :MockNode | MockNode[] { | ||
getNode(...keys :string[]) :RepoNodeWithData | RepoNodeWithData[] { | ||
// TODO support key as _path | ||
@@ -67,6 +133,6 @@ if (!keys.length) { | ||
const flattenedKeys :string[] = flatten(keys) as string[]; | ||
const nodes :MockNode[] = flattenedKeys.map(k => this._nodes[k]) as MockNode[]; | ||
const nodes :RepoNodeWithData[] = flattenedKeys.map(k => this._nodes[k]) as RepoNodeWithData[]; | ||
return nodes.length > 1 | ||
? nodes //as MockNode[] | ||
: nodes[0] as MockNode; | ||
? nodes //as RepoNodeWithData[] | ||
: nodes[0] as RepoNodeWithData; | ||
} | ||
@@ -77,6 +143,40 @@ | ||
editor | ||
} :MockNodeModifyParam) :MockNode { | ||
const node :MockNode = this.getNode(key) as MockNode; | ||
} :NodeModifyParams) :RepoNodeWithData { | ||
const node :RepoNodeWithData = this.getNode(key) as RepoNodeWithData; | ||
return editor(node); | ||
} | ||
//@ts-ignore | ||
query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
} :NodeQueryParams) :NodeQueryResponse { | ||
/*this.log.debug('param:%s', { | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
});*/ | ||
const ids = Object.keys(this._nodes); | ||
const total = ids.length; | ||
return { | ||
aggregations: {}, | ||
count: total, | ||
hits: ids.map(id => ({ | ||
id, | ||
score: 1 | ||
})), | ||
total | ||
}; | ||
} | ||
} // class Branch |
@@ -1,34 +0,44 @@ | ||
import type {Branch} from './Branch'; | ||
import type {Log} from './globals.d' | ||
import type { Branch } from './Branch'; | ||
import type { JavaBridge } from './JavaBridge'; | ||
import type { RepoNodeWithData } from './node/node.d'; | ||
import type { NodeCreateParams } from './node/create.d'; | ||
import type { NodeModifyParams } from './node/modify.d'; | ||
import type { NodeQueryParams } from './node/query'; | ||
import type { | ||
MockNode, | ||
MockNodeCreateParam, | ||
MockNodeModifyParam, | ||
MockRepoConnection | ||
} from './node.d'; | ||
NodeQueryResponse, | ||
RepoConnection | ||
} from './node/repoConnection.d'; | ||
export class Connection implements MockRepoConnection { | ||
export class Connection implements RepoConnection { | ||
private _branch :Branch; | ||
private _javaBridge :JavaBridge; | ||
readonly log :Log; | ||
constructor({ | ||
branch | ||
branch, | ||
javaBridge | ||
} :{ | ||
branch :Branch | ||
branch :Branch, | ||
javaBridge :JavaBridge | ||
}) { | ||
//console.debug('javaBridge.constructor.name', javaBridge.constructor.name); | ||
this._branch = branch; | ||
this._javaBridge = javaBridge; | ||
this.log = this._javaBridge.log; | ||
//this.log.debug('in Connection constructor'); | ||
} | ||
create({ | ||
//_id, | ||
_name, | ||
...rest | ||
} :MockNodeCreateParam) :MockNodeCreateParam { | ||
return this._branch.createNode({ | ||
//_id, | ||
_name, | ||
...rest | ||
}); | ||
create(param :NodeCreateParams) :RepoNodeWithData { | ||
return this._branch.createNode(param); | ||
} | ||
get(...keys :string[]) :MockNode | MockNode[] { | ||
/*get(key :string) :RepoNodeWithData { | ||
return this._branch.getNode(key); | ||
} | ||
get(keys :string[]) :RepoNodeWithData | RepoNodeWithData[] { | ||
return this._branch.getNode(keys); | ||
}*/ | ||
get(...keys :string[]) :RepoNodeWithData | RepoNodeWithData[] { | ||
return this._branch.getNode(...keys); | ||
@@ -40,3 +50,3 @@ } | ||
editor | ||
} :MockNodeModifyParam) :MockNode { | ||
} :NodeModifyParams) :RepoNodeWithData { | ||
return this._branch.modifyNode({ | ||
@@ -47,2 +57,24 @@ key, | ||
} | ||
query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
} :NodeQueryParams) :NodeQueryResponse { | ||
return this._branch.query({ | ||
aggregations, | ||
count, | ||
explain, | ||
filters, | ||
highlight, | ||
query, | ||
sort, | ||
start | ||
}); | ||
} | ||
} // class Connection |
@@ -6,5 +6,5 @@ import type { | ||
import type { | ||
MockRepoConnection, | ||
RepoConnection, | ||
Source | ||
} from './node.d'; | ||
} from './node/repoConnection.d'; | ||
import type { | ||
@@ -14,6 +14,6 @@ CreateRepoParams, | ||
RepositoryConfig | ||
} from './repo.d'; | ||
} from './repo/index.d'; | ||
import type { | ||
ValueLib | ||
} from './value.d'; | ||
} from './value/index.d'; | ||
@@ -47,2 +47,3 @@ import {Connection} from './Connection'; | ||
id, | ||
javaBridge: this, | ||
//rootPermissions, | ||
@@ -86,2 +87,3 @@ settings | ||
} | ||
//this.log.debug('in JavaBridge constructor'); | ||
} // constructor | ||
@@ -94,3 +96,3 @@ | ||
//principals | ||
} :Source) :MockRepoConnection { | ||
} :Source) :RepoConnection { | ||
const repo = this._repos[repoId]; | ||
@@ -101,5 +103,8 @@ if (!repo) { | ||
const branchObj = repo.getBranch(branch); | ||
const connection = new Connection({branch: branchObj}); | ||
const connection = new Connection({ | ||
branch: branchObj, | ||
javaBridge: this | ||
}); | ||
return connection; | ||
} | ||
} // class JavaBridge |
@@ -1,4 +0,5 @@ | ||
import type {RepositorySettings} from './repo.d'; | ||
import type {Log} from './globals.d' | ||
import type {RepositorySettings} from './repo/index.d'; | ||
import type {JavaBridge} from './JavaBridge'; | ||
import {Branch} from './Branch'; | ||
@@ -14,19 +15,29 @@ | ||
private _id :string; | ||
private _branches :Branches = { | ||
'master': new Branch() // This is where the nodes exist | ||
}; | ||
private _branches :Branches; | ||
private _javaBridge :JavaBridge; | ||
//rootChildOrder | ||
//rootPermissions | ||
private _settings :RepositorySettings; | ||
readonly log :Log; | ||
constructor({ | ||
id, | ||
javaBridge, | ||
settings = {} | ||
} :{ | ||
id :string | ||
javaBridge :JavaBridge | ||
settings? :RepositorySettings | ||
}) { | ||
//console.debug('javaBridge.constructor.name',javaBridge.constructor.name); | ||
this._id = id; | ||
//this._branches = ['master']; | ||
this._javaBridge = javaBridge; | ||
this.log = this._javaBridge.log; | ||
//this.log.debug('in Repo constructor'); | ||
this._settings = settings; | ||
this._branches = { | ||
'master': new Branch({ | ||
repo: this | ||
}) | ||
}; | ||
} | ||
@@ -33,0 +44,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1071434
220
28899