@saulx/selva
Advanced tools
Comparing version 0.2.20 to 0.2.22
@@ -5,2 +5,2 @@ import { GetItem, GetResult } from '~selva/get/types'; | ||
import { GetFieldFn } from './types'; | ||
export default function getArray(getField: GetFieldFn, props: GetItem[], schema: Schema, result: GetResult, id: Id, field: string, resultField: string, language?: string, version?: string, includeMeta?: boolean, ignore?: '$' | '$inherit' | '$list' | '$find' | '$filter'): boolean; | ||
export default function getArray(getField: GetFieldFn, props: GetItem[], schema: Schema, result: GetResult, id: Id, resultField: string, language?: string, version?: string, includeMeta?: boolean, ignore?: '$' | '$inherit' | '$list' | '$find' | '$filter'): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const nestedFields_1 = require("lua/src/get/nestedFields"); | ||
function getArray(getField, props, schema, result, id, field, resultField, language, version, includeMeta, ignore // when from inherit | ||
function getArray(getField, props, schema, result, id, resultField, language, version, includeMeta, ignore // when from inherit | ||
) { | ||
@@ -9,4 +9,9 @@ const resultAry = []; | ||
const intermediateResult = {}; | ||
getField(props[i], schema, intermediateResult, id, field, language, version, includeMeta, ignore); | ||
resultAry[i] = nestedFields_1.getNestedField(intermediateResult, field); | ||
getField(props[i], schema, intermediateResult, id, props[i].$id ? 'arrayPayload' : undefined, language, version, includeMeta, ignore); | ||
if (props[i].$id) { | ||
resultAry[i] = nestedFields_1.getNestedField(intermediateResult, 'arrayPayload'); | ||
} | ||
else { | ||
resultAry[i] = intermediateResult; | ||
} | ||
} | ||
@@ -13,0 +18,0 @@ nestedFields_1.setNestedResult(result, resultField, resultAry); |
@@ -32,2 +32,8 @@ "use strict"; | ||
} | ||
if (props.$id && field) { | ||
const intermediateResult = {}; | ||
const v = getField(props, schema, intermediateResult, props.$id, undefined, language, version, false, ignore); | ||
nestedFields_1.setNestedResult(result, field, intermediateResult); | ||
return true; | ||
} | ||
if ((props.$list || props.$find) && | ||
@@ -81,3 +87,3 @@ ignore !== '$list' && | ||
else if (util_1.isArray(props[key])) { | ||
getArray_1.default(getField, props[key], schema, result, id, field || '', f, language, version, includeMeta, ignore); | ||
getArray_1.default(getField, props[key], schema, result, id, f, language, version, includeMeta, ignore); | ||
} | ||
@@ -84,0 +90,0 @@ else { |
@@ -87,2 +87,5 @@ "use strict"; | ||
} | ||
if (operator === 'notExists') { | ||
return `-@_exists_${filter.$field}:{T}`; | ||
} | ||
if (type === 'TAG') { | ||
@@ -89,0 +92,0 @@ if (util_1.isArray(filter.$value)) { |
@@ -40,3 +40,4 @@ "use strict"; | ||
o === 'distance' || | ||
o === 'exists')) { | ||
o === 'exists' || | ||
o === 'notExists')) { | ||
return [{ isFork: true }, `Invalid filter operator ${o}`]; | ||
@@ -43,0 +44,0 @@ } |
@@ -5,3 +5,3 @@ import { Sort } from '~selva/get/types'; | ||
$field: string; | ||
$operator: '=' | '>' | '<' | '..' | '!=' | 'distance' | 'exists'; | ||
$operator: '=' | '>' | '<' | '..' | '!=' | 'distance' | 'exists' | 'notExists'; | ||
$value: Value; | ||
@@ -8,0 +8,0 @@ $search: string[]; |
@@ -70,2 +70,8 @@ "use strict"; | ||
exports.cleanUpSuggestions = cleanUpSuggestions; | ||
function cleanUpAliases(id) { | ||
const itemAliases = r.smembers(id + '.aliases'); | ||
for (const alias of itemAliases) { | ||
r.hdel('___selva_aliases', alias); | ||
} | ||
} | ||
function deleteItem(id, hierarchy = true) { | ||
@@ -95,2 +101,3 @@ if (hierarchy) { | ||
r.del(id + '._depth'); | ||
cleanUpAliases(id); | ||
events_1.default(id, '', 'delete'); | ||
@@ -97,0 +104,0 @@ const vals = r.hgetall(id); |
@@ -268,17 +268,36 @@ "use strict"; | ||
if (!payload.$id) { | ||
if (!payload.type) { | ||
if (payload.$alias) { | ||
const accessAliases = util_1.ensureArray(payload.$alias); | ||
for (const alias of accessAliases) { | ||
const id = redis.hget('___selva_aliases', alias); | ||
if (id && id !== '') { | ||
payload.$id = id; | ||
break; | ||
} | ||
} | ||
if (!payload.$id) { | ||
delete payload.$alias; | ||
if (!payload.aliases) { | ||
payload.aliases = accessAliases; | ||
} | ||
update(payload); | ||
} | ||
} | ||
else if (!payload.type) { | ||
return null; | ||
} | ||
const itemType = type(payload.type) === 'string' | ||
? payload.type | ||
: payload.type.$value; | ||
if ((payload.externalId && type(payload.externalId) === 'string') || | ||
util_1.isArray(payload.externalId)) { | ||
payload.$id = id_1.id({ | ||
type: itemType, | ||
externalId: payload.externalId | ||
}); | ||
} | ||
else { | ||
payload.$id = id_1.id({ type: itemType }); | ||
const itemType = type(payload.type) === 'string' | ||
? payload.type | ||
: payload.type.$value; | ||
if ((payload.externalId && type(payload.externalId) === 'string') || | ||
util_1.isArray(payload.externalId)) { | ||
payload.$id = id_1.id({ | ||
type: itemType, | ||
externalId: payload.externalId | ||
}); | ||
} | ||
else { | ||
payload.$id = id_1.id({ type: itemType }); | ||
} | ||
} | ||
@@ -285,0 +304,0 @@ } |
@@ -30,3 +30,3 @@ import Observable from '../observe/observable'; | ||
subscribe<T>(channel: string, getOpts: GetOptions): Observable<T>; | ||
queue(command: string, args: (string | number)[], resolve: (x: any) => void, reject: (x: Error) => void, subscriber?: boolean): Promise<void>; | ||
queue(command: string, args: (string | number)[], resolve: (x: any) => void, reject: (x: Error) => void, subscriber?: boolean, type?: string): Promise<void>; | ||
private batchEvalScriptArgs; | ||
@@ -33,0 +33,0 @@ private execBatch; |
@@ -66,15 +66,2 @@ "use strict"; | ||
if (!this.scriptShas[scriptName]) { | ||
/* | ||
* Node is really fucking nice | ||
* If I change this to | ||
* this.scriptShas[scriptName] = await this.loadScript(script) | ||
* | ||
* the whole functions shits the bed like this line doesn't even exist | ||
* and this.scriptShas is an empty object ({})... | ||
* which means that even if the promise was resolved wrong | ||
* the key doesn't exist at all, which it would if you did | ||
* this.scriptShas['hello'] = undefined // becomes { hello: undefined } | ||
* | ||
* Thaaaanks! | ||
*/ | ||
const r = await this.loadScript(script); | ||
@@ -106,4 +93,9 @@ this.scriptShas[scriptName] = r; | ||
this.retryTimer = 100; | ||
let tries = 0; | ||
if (!opts.retryStrategy) { | ||
opts.retryStrategy = () => { | ||
// console.log('RECON', tries) | ||
tries++; | ||
// needs to re do client | ||
// prob want a keep alive thing in here | ||
this.resetScripts(); | ||
@@ -113,3 +105,6 @@ this.connected = false; | ||
this.connector().then(async (newOpts) => { | ||
if (newOpts.host !== opts.host || newOpts.port !== opts.port) { | ||
if (newOpts.host !== opts.host || | ||
newOpts.port !== opts.port || | ||
tries > 15) { | ||
// console.log('HARD RECONN') | ||
this.client.quit(); | ||
@@ -127,2 +122,3 @@ this.connected = false; | ||
} | ||
// reconnecting | ||
this.subscriptionManager.connect(opts); | ||
@@ -132,3 +128,3 @@ // on dc needs to re run connector - if different reconnect | ||
this.client.on('error', err => { | ||
// console.log('ERRRRR') | ||
// console.log('ERR', err) | ||
if (err.code === 'ECONNREFUSED') { | ||
@@ -142,5 +138,8 @@ console.info(`Connecting to ${err.address}:${err.port}`); | ||
this.client.on('connect', _ => { | ||
// console.log('connect it', a) | ||
tries = 0; | ||
// console.log('connect it') | ||
}); | ||
this.client.on('ready', () => { | ||
// console.log('ready') | ||
tries = 0; | ||
this.retryTimer = 100; | ||
@@ -154,3 +153,6 @@ this.connected = true; | ||
} | ||
async queue(command, args, resolve, reject, subscriber) { | ||
async queue(command, args, resolve, reject, subscriber, type // need this for smart batching | ||
) { | ||
// NEED TYPE - REMOVE SUBSCRIBER | ||
// not good... | ||
if (subscriber) { | ||
@@ -162,2 +164,3 @@ // somewhere else! | ||
// // do we want to cache? | ||
// batch gets pretty nice to do | ||
// if (command === 'GET') { | ||
@@ -232,2 +235,3 @@ // // dont execute getting the same ids | ||
} | ||
// should not be just modify | ||
for (let sha in batchedModifyArgs) { | ||
@@ -239,2 +243,4 @@ const modifyArgs = batchedModifyArgs[sha]; | ||
slice.push({ | ||
// add type | ||
type: 'modify', | ||
command: 'evalsha', | ||
@@ -241,0 +247,0 @@ args: [sha, 0, ...modifyArgs], |
@@ -46,2 +46,8 @@ "use strict"; | ||
} | ||
else if (key === '$alias') { | ||
if (typeof payload[key] !== 'string' && !Array.isArray(payload[key])) { | ||
throw new Error('Wrong type for $alias, string or array required'); | ||
} | ||
result[key] = payload[key]; | ||
} | ||
else if (key === '$version') { | ||
@@ -75,7 +81,23 @@ if (typeof payload[key] !== 'string') { | ||
async function set(client, payload) { | ||
let gotSchema = false; | ||
if (!client.schema) { | ||
await client.getSchema(); | ||
gotSchema = true; | ||
} | ||
// need to check if it updated | ||
let schema = client.schema; | ||
const parsed = exports.parseSetObject(payload, schema); | ||
let parsed; | ||
try { | ||
parsed = exports.parseSetObject(payload, schema); | ||
} | ||
catch (err) { | ||
if (!gotSchema) { | ||
delete client.schema; | ||
return set(client, payload); | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
// need to check for error of schema | ||
const modifyResult = await client.modify({ | ||
@@ -85,2 +107,3 @@ kind: 'update', | ||
}); | ||
console.log(modifyResult); | ||
return modifyResult; | ||
@@ -87,0 +110,0 @@ } |
{ | ||
"name": "@saulx/selva", | ||
"version": "0.2.20", | ||
"version": "0.2.22", | ||
"main": "dist/src/index.js", | ||
@@ -75,3 +75,3 @@ "scripts": { | ||
"typescript-to-lua": "^0.30.1", | ||
"@saulx/selva-server": "0.2.17" | ||
"@saulx/selva-server": "0.2.19" | ||
}, | ||
@@ -78,0 +78,0 @@ "dependencies": { |
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 not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
937048
7823