Skip to content

Commit

Permalink
Merge in progress don't run
Browse files Browse the repository at this point in the history
New Request Object Class
New Response Object Class
Seperation of Data & Logic
Base Classes
  • Loading branch information
Universal Web committed Sep 26, 2023
1 parent 0c706f1 commit ac718ef
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 473 deletions.
4 changes: 2 additions & 2 deletions udsp/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './client/index.js';
export * from './server/index.js';
export * from './request/requestObject.js';
export * from './request/client/clientResponse.js';
export * from './request/objects/client/request';
export * from './request/objects/client/response.js';
29 changes: 12 additions & 17 deletions udsp/request/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
failed, info, msgReceived, msgSent
} from '#logs';
import { Base } from './base.js';
import { clientResponse } from './client/clientResponse.js';
import { clientResponse } from './objects/client/response.js';
import { objectGetSetMethods } from './objects/objectGetSetMethods.js';
import { ClientRequest } from './objects/client/request.js';
export class Ask extends Base {
constructor(method = 'get', path, parameters, data, head, options = {}, source) {
super(options, source);
Expand All @@ -25,20 +27,14 @@ export class Ask extends Base {
this.request.method = methodSanitized;
this.method = methodSanitized;
this.id = streamId;
if (path) {
this.request.path = path;
this.path = path;
}
if (parameters) {
this.request.parameters = parameters;
this.parameters = parameters;
}
if (data) {
this.request.data = data;
}
if (head) {
this.request.head = head;
}
this.request = new ClientRequest(path, {
method,
parameters,
data,
head,
source: this
});
this.response = clientResponse(this);
requestQueue.set(streamId, this);
}
completeReceived() {
Expand All @@ -48,8 +44,7 @@ export class Ask extends Base {
}
this.readyState = 4;
this.flush();
const response = clientResponse(this);
this.accept(response);
this.accept(this.response);
}
isAsk = true;
type = 'ask';
Expand Down
115 changes: 27 additions & 88 deletions udsp/request/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import { on } from './on.js';
import { flushOutgoing, flushIncoming, flush } from './flush.js';
import { onPacket } from './onPacket.js';
import {
isBuffer, isPlainObject, isString, promise, assign,
objectSize, eachArray, jsonParse, construct, isArray, clear, isFalse, isTrue, clearBuffer, hasValue
isBuffer,
isPlainObject,
isString,
promise,
assign,
objectSize, eachArray, jsonParse,
construct, isArray, clear, isFalse,
isTrue, clearBuffer, hasValue
} from '@universalweb/acid';
import { encode, decode } from 'msgpackr';
import { toBase64 } from '#crypto';
Expand Down Expand Up @@ -91,6 +97,11 @@ export class Base {
} else {
this.head = {};
}
if (this.isAsk) {
this.response.head = this.head;
} else {
this.request.head = this.head;
}
this.readyState = 2;
this.headAssembled = true;
}
Expand All @@ -105,6 +116,11 @@ export class Base {
} else {
this.parameters = null;
}
if (this.isAsk) {
this.response.parameters = this.parameters;
} else {
this.request.parameters = this.parameters;
}
this.readyState = 2;
this.parametersAssembled = true;
}
Expand All @@ -119,6 +135,11 @@ export class Base {
} else {
this.path = '';
}
if (this.isAsk) {
this.response.path = this.path;
} else {
this.request.path = this.path;
}
this.readyState = 2;
this.pathAssembled = true;
}
Expand Down Expand Up @@ -213,29 +234,12 @@ export class Base {
console.log('Missing packets: ', missingDataPackets);
} else if (this.head.dataSize === this.currentIncomingDataSize) {
this.completeReceived();
}
}
get data() {
if (this.compiledDataAlready) {
return this.compiledData;
}
this.incomingDataPackets = null;
const { head: { serialize } } = this;
const dataConcatinated = Buffer.concat(this.incomingData);
this.incomingData.fill(0);
this.incomingData = null;
if (serialize) {
if (isTrue(serialize)) {
this.compiledData = decode(dataConcatinated);
} else if (serialize === 1) {
this.compiledData = jsonParse(dataConcatinated);
if (this.isAsk) {
this.response.dataBuffer = this.incomingData;
} else {
this.request.dataBuffer = this.incomingData;
}
dataConcatinated.fill(0);
} else {
this.compiledData = dataConcatinated;
}
this.compiledDataAlready = true;
return this.compiledData;
}
sendSetup() {
const { isAsk } = this;
Expand Down Expand Up @@ -512,70 +516,6 @@ export class Base {
};
return message;
}
toString(cache) {
if (cache) {
if (this.toStringCached) {
return this.toStringCached;
}
}
const target = this.data.toString();
if (cache) {
this.toStringCached = target;
}
return target;
}
toJSON(cache) {
if (cache) {
if (this.toJSONCached) {
return this.toJSONCached;
}
}
const target = jsonParse(this.data);
if (cache) {
this.toJSONCached = target;
}
return jsonParse(this.data);
}
serialize(cache) {
if (cache) {
if (this.serializeCached) {
return this.serializeCached;
}
}
const target = decode(this.data);
if (cache) {
this.serializeCached = target;
}
return target;
}
toObject(cache) {
if (cache) {
if (this.toObjectRawCached) {
return this.toObjectRawCached;
}
}
const {
head,
data,
id,
method,
} = this;
const target = {
head,
data,
method
};
if (cache) {
this.toObjectRawCached = target;
}
return target;
}
get headers() {
return this.head;
}
get body() {
return this.data;
}
destroy = destroy;
onPacket = onPacket;
sendPacket(message, headers, footer) {
Expand Down Expand Up @@ -646,5 +586,4 @@ export class Base {
outgoingParametersSize = 0;
outgoingHeadSize = 0;
outgoingDataSize = 0;
bg = 0;
}
164 changes: 0 additions & 164 deletions udsp/request/client/clientResponse.js

This file was deleted.

Loading

0 comments on commit ac718ef

Please sign in to comment.