@saulx/selva
Advanced tools
Comparing version 13.1.0 to 14.0.0
import { LogLevel } from './logger'; | ||
export declare function Error(errorMsg: string): Error; | ||
export declare function log(clientId: string, loglevel: LogLevel, msg: any): void; | ||
export declare function types_clear(): void; | ||
export declare function types_add(prefix: string, name: string): void; | ||
export declare function id(externalIdStr?: string): string; | ||
@@ -5,0 +7,0 @@ export declare function delnode(id: string): any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ping = exports.del = exports.get = exports.set = exports.pexpire = exports.expire = exports.exists = exports.zscore = exports.zrange = exports.zrangeWithScores = exports.zAddReplaceScore = exports.zaddNew = exports.zAddMultipleNew = exports.srem = exports.scard = exports.sunion = exports.smembers = exports.sismember = exports.sadd = exports.hincrby = exports.debug = exports.hdel = exports.hsetnx = exports.hset = exports.hkeys = exports.hmget = exports.hgetall = exports.hget = exports.hexists = exports.descendants = exports.ancestors = exports.parents = exports.children = exports.delnode = exports.id = exports.log = exports.Error = void 0; | ||
exports.ping = exports.del = exports.get = exports.set = exports.pexpire = exports.expire = exports.exists = exports.zscore = exports.zrange = exports.zrangeWithScores = exports.zAddReplaceScore = exports.zaddNew = exports.zAddMultipleNew = exports.srem = exports.scard = exports.sunion = exports.smembers = exports.sismember = exports.sadd = exports.hincrby = exports.debug = exports.hdel = exports.hsetnx = exports.hset = exports.hkeys = exports.hmget = exports.hgetall = exports.hget = exports.hexists = exports.descendants = exports.ancestors = exports.parents = exports.children = exports.delnode = exports.id = exports.types_add = exports.types_clear = exports.log = exports.Error = void 0; | ||
const DEFAULT_HIERARCHY = '___selva_hierarchy'; | ||
@@ -13,2 +13,10 @@ function Error(errorMsg) { | ||
exports.log = log; | ||
function types_clear() { | ||
redis.call('selva.hierarchy.types.clear', DEFAULT_HIERARCHY); | ||
} | ||
exports.types_clear = types_clear; | ||
function types_add(prefix, name) { | ||
redis.call('selva.hierarchy.types.add', DEFAULT_HIERARCHY, prefix, name); | ||
} | ||
exports.types_add = types_add; | ||
function id(externalIdStr) { | ||
@@ -15,0 +23,0 @@ if (externalIdStr) { |
@@ -77,2 +77,6 @@ "use strict"; | ||
constructPrefixMap(schema); | ||
r.types_clear(); | ||
for (const prefix in schema.prefixToTypeMapping) { | ||
r.types_add(prefix, schema.prefixToTypeMapping[prefix]); | ||
} | ||
let encoded = cjson.encode(schema); | ||
@@ -79,0 +83,0 @@ const sha = redis.sha1hex(encoded); |
@@ -9,3 +9,2 @@ export declare const arrayIsEqual: (a: any[], b: any[]) => boolean; | ||
export declare function adler32(str: string): number; | ||
export declare function subscriptionAddField(id: string, field: string): void; | ||
export declare function stringStartsWith(str: string, slice: string): boolean; | ||
@@ -12,0 +11,0 @@ export declare function stringEndsWith(str: string, slice: string): boolean; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isTextIndex = exports.now = exports.indexOf = exports.objectAssign = exports.testString = exports.isEqual = exports.escapeSpecial = exports.markEmptyArraysInJSON = exports.emptyArray = exports.ensureArray = exports.stringEndsWith = exports.stringStartsWith = exports.subscriptionAddField = exports.adler32 = exports.joinAny = exports.joinPaddedIds = exports.joinString = exports.splitString = exports.isArray = exports.isString = exports.arrayIsEqual = void 0; | ||
exports.isTextIndex = exports.now = exports.indexOf = exports.objectAssign = exports.testString = exports.isEqual = exports.escapeSpecial = exports.markEmptyArraysInJSON = exports.emptyArray = exports.ensureArray = exports.stringEndsWith = exports.stringStartsWith = exports.adler32 = exports.joinAny = exports.joinPaddedIds = exports.joinString = exports.splitString = exports.isArray = exports.isString = exports.arrayIsEqual = void 0; | ||
const globals_1 = __importDefault(require("./globals")); | ||
@@ -129,12 +129,2 @@ const NODE_ID_SIZE = 10; | ||
exports.adler32 = adler32; | ||
function subscriptionAddField(id, field) { | ||
if (!globals_1.default.$subscription || globals_1.default.$traversing) { | ||
return; | ||
} | ||
// FIXME: does this make sense? | ||
const markerId = adler32(id + '#fields'); | ||
redis.call('SELVA.SUBSCRIPTIONS.ADD', '___selva_hierarchy', globals_1.default.$subscription, String(markerId), 'node'); | ||
redis.call('SELVA.SUBSCRIPTIONS.addMarkerField', '___selva_hierarchy', globals_1.default.$subscription, String(markerId), field); | ||
} | ||
exports.subscriptionAddField = subscriptionAddField; | ||
function stringStartsWith(str, slice) { | ||
@@ -141,0 +131,0 @@ if (slice.length > str.length) { |
@@ -52,2 +52,3 @@ "use strict"; | ||
'selva.modify', | ||
'selva.update', | ||
'selva.object.del', | ||
@@ -75,6 +76,8 @@ 'selva.object.exists', | ||
'selva.hierarchy.listcompressed', | ||
'selva.hierarchy.types.add', | ||
'selva.hierarchy.types.clear', | ||
'selva.hierarchy.types.list', | ||
'selva.inherit', | ||
'selva.resolve.nodeid', | ||
'selva.subscriptions.add', | ||
'selva.subscriptions.addmarkerfields', | ||
'selva.subscriptions.addalias', | ||
@@ -81,0 +84,0 @@ 'selva.subscriptions.addmissing', |
@@ -7,3 +7,3 @@ "use strict"; | ||
/* <BEGIN_INSERT_SCRIPTS */ | ||
'update-schema': 'ff715569760a94b129feb09e2ab6569adf97a426', | ||
'update-schema': '04a867e2db0e4ea31c849b038157c97bc5a9388d', | ||
/* <END_INSERT_SCRIPTS */ | ||
@@ -10,0 +10,0 @@ // END OF THE AUTOGENERATED PORTION |
@@ -499,6 +499,8 @@ "use strict"; | ||
const nestedFieldSchema = (0, utils_1.getNestedSchema)(schema, nestedId, nestedField); | ||
if ((nestedFieldSchema === null || nestedFieldSchema === void 0 ? void 0 : nestedFieldSchema.type) === 'reference' && isNestedObject(nestedValue)) { | ||
if ((nestedFieldSchema === null || nestedFieldSchema === void 0 ? void 0 : nestedFieldSchema.type) === 'reference' && | ||
isNestedObject(nestedValue)) { | ||
parseNestedFieldReference(fullPath, nestedValue[0]); | ||
} | ||
else if ((nestedFieldSchema === null || nestedFieldSchema === void 0 ? void 0 : nestedFieldSchema.type) === 'references' && isNestedObject(nestedValue)) { | ||
else if ((nestedFieldSchema === null || nestedFieldSchema === void 0 ? void 0 : nestedFieldSchema.type) === 'references' && | ||
isNestedObject(nestedValue)) { | ||
for (let i = 0; i < value.length; i++) { | ||
@@ -514,9 +516,11 @@ parseNestedFieldReference(`${fullPath}[]`, nestedValue[i]); | ||
// TODO This won't work? | ||
//for (const f of targetField) { | ||
// for (const f of targetField) { | ||
// setNestedResult(entryRes, f, casted) | ||
//} | ||
// } | ||
} | ||
else { | ||
if (isReferences) { | ||
(0, utils_1.setNestedResult)(entryRes, path.slice(0, -2), [{ [nestedField]: casted }]); | ||
(0, utils_1.setNestedResult)(entryRes, path.slice(0, -2), [ | ||
{ [nestedField]: casted }, | ||
]); | ||
} | ||
@@ -534,3 +538,4 @@ else { | ||
} | ||
else if ((sourceFieldSchema === null || sourceFieldSchema === void 0 ? void 0 : sourceFieldSchema.type) === 'references' && isNestedObject(value)) { | ||
else if ((sourceFieldSchema === null || sourceFieldSchema === void 0 ? void 0 : sourceFieldSchema.type) === 'references' && | ||
isNestedObject(value)) { | ||
for (let i = 0; i < value.length; i++) { | ||
@@ -537,0 +542,0 @@ parseNestedFieldReference(`${field}[]`, value[i]); |
@@ -16,3 +16,4 @@ /// <reference types="node" /> | ||
import { ObservableOptions, ObsSettings } from './observable/types'; | ||
import { SetMetaResponse } from './set/types'; | ||
import { SetMetaResponse, SetItem } from './set/types'; | ||
import { UpdateQuery } from './update'; | ||
export * as constants from './constants'; | ||
@@ -68,2 +69,5 @@ export declare class SelvaClient extends EventEmitter { | ||
get(getOpts: GetOptions): Promise<GetResult>; | ||
update(setOpts: Omit<SetItem, '$id' | '$alias'> & { | ||
$db?: string; | ||
}, query: UpdateQuery): Promise<boolean | void>; | ||
set(setOpts: SetOptions, schema?: Schema): Promise<Id | undefined>; | ||
@@ -70,0 +74,0 @@ setWithMeta(setOpts: SetOptions): Promise<SetMetaResponse | undefined>; |
@@ -51,2 +51,3 @@ "use strict"; | ||
const extractSchemaDelOpts_1 = __importDefault(require("./schema/extractSchemaDelOpts")); | ||
const update_1 = require("./update"); | ||
exports.constants = __importStar(require("./constants")); | ||
@@ -126,2 +127,6 @@ let clientId = 0; | ||
} | ||
async update(setOpts, query) { | ||
await this.initializeSchema(setOpts); | ||
return (0, update_1.update)(this, setOpts, query); | ||
} | ||
async set(setOpts, schema) { | ||
@@ -128,0 +133,0 @@ await this.initializeSchema(setOpts); |
@@ -394,3 +394,3 @@ "use strict"; | ||
const versions = JSON.parse(msg); | ||
if (versions && versions[0] === this.version && !getOptions.$trigger) { | ||
if (versions && versions[0] === this.version && !(getOptions === null || getOptions === void 0 ? void 0 : getOptions.$trigger)) { | ||
// is the same ignore | ||
@@ -397,0 +397,0 @@ } |
@@ -487,2 +487,8 @@ /// <reference types="node" /> | ||
selva_hierarchy_listcompressed(...args: args): Promise<any>; | ||
selva_hierarchy_types_add(opts: ServerSelector, ...args: args): Promise<any>; | ||
selva_hierarchy_types_add(...args: args): Promise<any>; | ||
selva_hierarchy_types_clear(opts: ServerSelector, ...args: args): Promise<any>; | ||
selva_hierarchy_types_clear(...args: args): Promise<any>; | ||
selva_hierarchy_types_list(opts: ServerSelector, ...args: args): Promise<any>; | ||
selva_hierarchy_types_list(...args: args): Promise<any>; | ||
selva_inherit(opts: ServerSelector, ...args: args): Promise<any>; | ||
@@ -492,2 +498,4 @@ selva_inherit(...args: args): Promise<any>; | ||
selva_modify(...args: args): Promise<any>; | ||
selva_update(opts: ServerSelector, ...args: args): Promise<any>; | ||
selva_update(...args: args): Promise<any>; | ||
selva_resolve_nodeid(opts: ServerSelector, ...args: args): Promise<any>; | ||
@@ -513,4 +521,2 @@ selva_resolve_nodeid(...args: args): Promise<any>; | ||
selva_subscriptions_add(...args: args): Promise<any>; | ||
selva_subscriptions_addmarkerfields(opts: ServerSelector, ...args: args): Promise<any>; | ||
selva_subscriptions_addmarkerfields(...args: args): Promise<any>; | ||
selva_subscriptions_addalias(opts: ServerSelector, ...args: args): Promise<any>; | ||
@@ -517,0 +523,0 @@ selva_subscriptions_addalias(...args: args): Promise<any>; |
@@ -316,3 +316,4 @@ "use strict"; | ||
if (updated) { | ||
client.schemas[selector.name] = JSON.parse(updated); | ||
const schema = JSON.parse(updated); | ||
client.schemas[selector.name] = schema; | ||
} | ||
@@ -319,0 +320,0 @@ } |
import { SetOptions } from './types'; | ||
import { Schema } from '../schema'; | ||
import { SelvaClient } from '..'; | ||
export default function parseSetObject(client: SelvaClient, payload: SetOptions, schemas: Schema, $lang?: string): Promise<string[]>; | ||
export default function parseSetObject(client: SelvaClient, payload: SetOptions, schemas: Schema, $lang?: string, noTarget?: boolean): Promise<string[]>; |
@@ -52,15 +52,20 @@ "use strict"; | ||
} | ||
async function parseSetObject(client, payload, schemas, $lang) { | ||
async function parseSetObject(client, payload, schemas, $lang, noTarget) { | ||
var _a, _b; | ||
// id, R|N, field enum, fieldName, value | ||
const result = ['']; | ||
if (!payload.$id && !payload.$alias) { | ||
payload.$id = await client.id({ | ||
db: payload.$db || 'default', | ||
type: payload.type, | ||
}); | ||
if (noTarget) { | ||
// dont do too many things special | ||
} | ||
if (payload.$id) { | ||
; | ||
result.$id = payload.$id; | ||
else { | ||
if (!payload.$id && !payload.$alias) { | ||
payload.$id = await client.id({ | ||
db: payload.$db || 'default', | ||
type: payload.type, | ||
}); | ||
} | ||
if (payload.$id) { | ||
; | ||
result.$id = payload.$id; | ||
} | ||
} | ||
@@ -101,3 +106,6 @@ if (payload.$db) { | ||
for (const key in payload) { | ||
if (key[0] === '$') { | ||
if (key === 'type') { | ||
// Drop | ||
} | ||
else if (key[0] === '$') { | ||
if (key === '$merge') { | ||
@@ -180,2 +188,6 @@ if (!(payload[key] === true || payload[key] === false)) { | ||
} | ||
// Only send type field if there are no other changes | ||
if (result.length <= 1) { | ||
result.push('0', 'type', payload.type); | ||
} | ||
return result; | ||
@@ -182,0 +194,0 @@ } |
{ | ||
"name": "@saulx/selva", | ||
"version": "13.1.0", | ||
"version": "14.0.0", | ||
"main": "dist/src/index.js", | ||
@@ -53,3 +53,3 @@ "scripts": { | ||
"@types/pg": "^8.6.1", | ||
"@saulx/selva-server": "13.1.0", | ||
"@saulx/selva-server": "14.0.0", | ||
"before-exit": "1.0.0", | ||
@@ -56,0 +56,0 @@ "async-exec": "^1.1.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
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 too big to display
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
1202969
315
16632