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

@aire-ux/aire-condensation

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aire-ux/aire-condensation - npm Package Compare versions

Comparing version 0.1.7 to 0.2.0

6

dist/condensation.js

@@ -86,9 +86,9 @@ import TypeRegistry from "./type-registry";

return ctorArgs.map((def, idx) => {
const doc = args[idx];
const doc = args[idx], jsonValue = JSON.parse(doc);
if (def.type !== Dynamic) {
const deserializer = Condensation.deserializerFor(def.type);
return deserializer.read(deserializer.primitive ? doc : JSON.parse(doc));
return deserializer.read(jsonValue);
}
else {
return JSON.parse(doc);
return jsonValue;
}

@@ -95,0 +95,0 @@ });

@@ -5,15 +5,11 @@ import "reflect-metadata";

export interface Deserializer<T> {
primitive: boolean;
read(object: any): T;
}
export declare class StringDeserializer implements Deserializer<string> {
primitive: boolean;
read(object: any): string;
}
export declare class BooleanDeserializer implements Deserializer<boolean> {
primitive: boolean;
read(object: any): boolean;
}
export declare class NumberDeserializer implements Deserializer<number> {
primitive: boolean;
read(object: any): number;

@@ -24,3 +20,2 @@ }

readonly registration: TypeRegistration<T>;
primitive: boolean;
constructor(type: Class<T>, registration: TypeRegistration<T>);

@@ -27,0 +22,0 @@ read(value: any): T;

import "reflect-metadata";
import { Condensation } from "./condensation";
export class StringDeserializer {
constructor() {
this.primitive = true;
}
read(object) {

@@ -12,5 +9,2 @@ return object;

export class BooleanDeserializer {
constructor() {
this.primitive = true;
}
read(object) {

@@ -21,5 +15,2 @@ return object;

export class NumberDeserializer {
constructor() {
this.primitive = true;
}
read(object) {

@@ -33,3 +24,2 @@ return object;

this.registration = registration;
this.primitive = false;
}

@@ -36,0 +26,0 @@ read(value) {

{
"name": "@aire-ux/aire-condensation",
"version": "0.1.7",
"version": "0.2.0",
"description": "Client-side serialization library for Aire-UX",

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

# Overview
Condensation is a library that allows transparent client-server communication for @aire-ux/component
widgets.
Condensation is a library for transparently hydrating JavaScript or
TypeScript objects from a variety of formats
(JSON, XML, Avro, gRPC, Cap'n Proto)
## Usage
### JVM/Java
This process is optional, but if you use a JVM language and servlet technologies, then you
can map your JVM objects directly to Condensation-mapped objects and call methods remotely
### Define the AireServlet

@@ -16,3 +22,3 @@

### DTO
# Generic Usage (backend-agnostic)

@@ -34,6 +40,88 @@ Define a data-transfer object:

city: string;
showInfo() : void {
console.log(`City: ${this.city}, Rooms: ${this.roomCount}`)
}
}
```
This object may be mounted from the following JSON document:
```json
{
"room-count": 4,
"city": "Fort Collins"
}
```
```typescript
/**
this context can be made a global object
*/
const context = Condensation.newContext();
const jsonDoc = await load('path/to/my/address'); // path returning above document
const address = ctx.create(Address, jsonDoc);
address.showInfo();
// logs City: Fort Collins, Rooms: 4
```
Condensation is capable of serializing/deserializing entire object-graphs,
including graphs that contain cycles:
```typescript
@Remotable
@RootElement
class Person {
@Identity
@Property(String)
commonName: string;
@Identity
@Property({
type: String,
read: {
alias: 'given-name' // can be read from "given-name" payload property
},
write: {
alias: 'GivenName' // will be written to "GivenName" payload property on write
}
})
givenName: string;
constructor(
@Linked(via = "children")
@Receive(Person) public readonly parents: Array<Person>,
@Linked(via = "parents")
@Receive(Person) public readonly children: Array<Person>
) {
}
}
```
input document
```json
[
{
"common-name": "Haswell",
"given-name": "Dad"
},
{
"common-name": "Haswell",
"given-name": "Josiah",
"parent": "Dad" // generated from commonName property of Identity. @Linked annotations will correctly link Dad -> Josiah via parent and children properties
}
]
```
```typescript
@RootElement
class Person {
@Property(String)

@@ -76,1 +164,3 @@ name: string | undefined;

```

@@ -174,8 +174,9 @@ import TypeRegistry from "@condensation/type-registry";

return ctorArgs.map((def, idx) => {
const doc = args[idx];
const doc = args[idx],
jsonValue = JSON.parse(doc);
if (def.type !== Dynamic) {
const deserializer = Condensation.deserializerFor(def.type);
return deserializer.read(deserializer.primitive ? doc : JSON.parse(doc));
return deserializer.read(jsonValue);
} else {
return JSON.parse(doc);
return jsonValue;
}

@@ -182,0 +183,0 @@ });

@@ -7,3 +7,2 @@ import "reflect-metadata";

export interface Deserializer<T> {
primitive: boolean;
read(object: any): T;

@@ -13,3 +12,2 @@ }

export class StringDeserializer implements Deserializer<string> {
primitive = true;
read(object: any): string {

@@ -21,3 +19,2 @@ return object as string;

export class BooleanDeserializer implements Deserializer<boolean> {
primitive = true;
read(object: any): boolean {

@@ -29,3 +26,2 @@ return object as boolean;

export class NumberDeserializer implements Deserializer<number> {
primitive = true;
read(object: any): number {

@@ -37,3 +33,2 @@ return object as number;

export class TypeRegistrationDeserializer<T> implements Deserializer<T> {
primitive = false;
constructor(

@@ -40,0 +35,0 @@ readonly type: Class<T>,

import { Condensation, Context } from "@condensation/condensation";
import { Property, RootElement } from "@condensation/root-element";
import {Receive, Remotable, Remote} from "@condensation/remotable";
import { Receive, Remotable } from "@condensation/remotable";
import { allocate, Region } from "@condensation/types";

@@ -55,48 +55,2 @@

test('objects should be able to receive escaped string primitives', () => {
@Remotable
class RemotePerson {
firstName: string | undefined;
@Remote
setFirstName(@Receive(String) name: string) : void {
this.firstName = name;
}
}
const value = context.create<RemotePerson>(
RemotePerson
);
context.invoke(value, 'setFirstName', "Josiah");
expect(value.firstName).toBe("Josiah");
});
test('objects should be able to receive string primitives', () => {
@Remotable
class RemotePerson {
firstName: string | undefined;
@Remote
setFirstName(@Receive(String) name: string) : void {
this.firstName = name;
}
}
const value = context.create<RemotePerson>(
RemotePerson
);
context.invoke(value, 'setFirstName', "Josiah");
expect(value.firstName).toBe("Josiah");
});
test("objects should be invocable by their handles", () => {

@@ -103,0 +57,0 @@ @RootElement

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