Socket
Socket
Sign inDemoInstall

ozone-type

Package Overview
Dependencies
Maintainers
5
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ozone-type - npm Package Compare versions

Comparing version 5.3.0 to 5.4.0

2

dist/model/FileType.d.ts

@@ -14,3 +14,3 @@ /**

export interface FileType {
id?: string;
id: string;
identifier: string;

@@ -17,0 +17,0 @@ uti?: string;

@@ -42,9 +42,2 @@ export declare type UUID = string;

}
export declare type FromOzone<T extends Item> = T & {
id: UUID;
version: UUID;
_meta: ItemMeta;
tenant: UUID;
type: string;
};
export declare type AbsentFromPatchProps = '_meta' | 'creationUser' | 'modificationUser';

@@ -58,2 +51,24 @@ export declare type NonNullablePatchProps = 'id' | 'version' | 'type';

};
/**
* template type for item received from ozone
*/
export declare type FromOzone<T extends Item> = T & {
id: UUID;
version: UUID;
_meta: ItemMeta;
tenant: UUID;
type: string;
};
/**
* Transform an item to an object than can be saved.
* undefined values (not be modify on ozone)
* @param item
*/
export declare function toPatch<T extends Item>(item: T): Patch<T>;
/**
* Transform an item to an object than can be saved
* undefined value will be set to null (erase on ozone)
* @param item
*/
export declare function toPatchWithUndefinedAsNull<T extends Item>(item: T): Patch<T>;
export declare class Item {

@@ -75,2 +90,7 @@ id?: UUID;

}
/**
* Decorator for class that extend ozone item
* @param typeIdentifier
* @constructor
*/
export declare function OzoneType(typeIdentifier: string): <T extends new (...args: any[]) => {}>(constructor: T) => {

@@ -77,0 +97,0 @@ new (...args: any[]): {

@@ -34,24 +34,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

})(Persistence || (Persistence = {}));
let Item = class Item {
constructor(src) {
if (src) {
this.id = src.id;
this.version = src.version;
this.type = src.type;
this._meta = src._meta;
this.name = src.name;
this.deleted = src.deleted;
this.traits = src.traits;
this.tenant = src.tenant;
this.creationUser = src.creationUser;
this.modificationUser = src.modificationUser;
}
}
};
Item = __decorate([
OzoneType('item'),
__metadata("design:paramtypes", [Item])
], Item);
export { Item };
function toPatch(item) {
/**
* Transform an item to an object than can be saved.
* undefined values (not be modify on ozone)
* @param item
*/
export function toPatch(item) {
let patch = {};

@@ -69,3 +53,8 @@ for (let prop of Object.getOwnPropertyNames(item)) {

}
function toPatchWithUndefinedAsNull(item) {
/**
* Transform an item to an object than can be saved
* undefined value will be set to null (erase on ozone)
* @param item
*/
export function toPatchWithUndefinedAsNull(item) {
let patch = {};

@@ -86,4 +75,30 @@ for (let prop of Object.getOwnPropertyNames(item)) {

}
let Item = class Item {
constructor(src) {
if (src) {
this.id = src.id;
this.version = src.version;
this.type = src.type;
this._meta = src._meta;
this.name = src.name;
this.deleted = src.deleted;
this.traits = src.traits;
this.tenant = src.tenant;
this.creationUser = src.creationUser;
this.modificationUser = src.modificationUser;
}
}
};
Item = __decorate([
OzoneType('item'),
__metadata("design:paramtypes", [Item])
], Item);
export { Item };
export class GenericItem extends Item {
}
/**
* Decorator for class that extend ozone item
* @param typeIdentifier
* @constructor
*/
export function OzoneType(typeIdentifier) {

@@ -90,0 +105,0 @@ return function (constructor) {

@@ -570,2 +570,1 @@ export * from './AdminPermission';

export * from './WildcardQuery';
export declare type UUID = string;

@@ -6,4 +6,4 @@ /**

* OpenAPI spec version: 3.0.0
*
*
*
* NOTE: This class is auto generated by the swagger code generator program.

@@ -17,3 +17,3 @@ * https://github.com/swagger-api/swagger-codegen.git

export interface FileType {
id?: string;
id: string;

@@ -20,0 +20,0 @@ identifier: string;

@@ -5,4 +5,4 @@ export type UUID = string

export interface ItemError {
fields?: string[]
message?: string
fields?: string[]
message?: string
}

@@ -17,9 +17,9 @@

export interface ItemMeta {
state: State
validity: Validity
security: Security
persistence: Persistence
validityErrors?: ValidityError[]
securityErrors?: SecurityError[]
persistenceErrors?: PersistenceError[]
state: State
validity: Validity
security: Security
persistence: Persistence
validityErrors?: ValidityError[]
securityErrors?: SecurityError[]
persistenceErrors?: PersistenceError[]
}

@@ -36,10 +36,2 @@

export type FromOzone<T extends Item> = T & {
id: UUID
version: UUID
_meta: ItemMeta
tenant: UUID
type: string
}
export type AbsentFromPatchProps = '_meta' | 'creationUser' | 'modificationUser'

@@ -57,71 +49,97 @@

@OzoneType('item')
export class Item {
id?: UUID
version?: UUID
type?:string
_meta?: ItemMeta
name?: string
deleted?: boolean
traits?: string[]
tenant?: UUID
creationUser?: UUID
modificationUser?: UUID
/**
* template type for item received from ozone
*/
export type FromOzone<T extends Item> = T & {
id: UUID
version: UUID
_meta: ItemMeta
tenant: UUID
type: string
}
constructor (src?: Item) {
if (src) {
this.id = src.id
this.version = src.version
this.type = src.type
this._meta = src._meta
this.name = src.name
this.deleted = src.deleted
this.traits = src.traits
this.tenant = src.tenant
this.creationUser = src.creationUser
this.modificationUser = src.modificationUser
}
}
/**
* Transform an item to an object than can be saved.
* undefined values (not be modify on ozone)
* @param item
*/
export function toPatch<T extends Item>(item: T): Patch<T> {
let patch: any = {}
for (let prop of Object.getOwnPropertyNames(item)) {
if (prop in ['_meta', 'creationUser', 'modificationUser']) {
continue
}
const val: any = (item as any)[prop]
if (val !== undefined) {
patch[prop] = val
}
}
return patch as Patch<T>
}
function toPatch<T extends Item>(item:T): Patch<T> {
let patch : any = {}
for (let prop of Object.getOwnPropertyNames(item)) {
if (prop in ['_meta', 'creationUser', 'modificationUser']) {
continue
}
const val:any = (item as any)[prop]
if (val !== undefined) {
patch[prop] = val
}
}
return patch as Patch<T>
/**
* Transform an item to an object than can be saved
* undefined value will be set to null (erase on ozone)
* @param item
*/
export function toPatchWithUndefinedAsNull<T extends Item>(item: T): Patch<T> {
let patch: any = {}
for (let prop of Object.getOwnPropertyNames(item)) {
if (prop in ['_meta', 'creationUser', 'modificationUser']) {
continue
}
const val: any = (item as any)[prop]
if (val === undefined) {
patch[prop] = null
} else {
patch[prop] = val
}
}
return patch as Patch<T>
}
function toPatchWithUndefinedAsNull<T extends Item>(item:T): Patch<T> {
let patch : any = {}
for (let prop of Object.getOwnPropertyNames(item)) {
if (prop in ['_meta', 'creationUser', 'modificationUser']) {
continue
}
const val:any = (item as any)[prop]
if (val === undefined) {
patch[prop] = null
} else {
patch[prop] = val
}
}
return patch as Patch<T>
@OzoneType('item')
export class Item {
id?: UUID
version?: UUID
type?: string
_meta?: ItemMeta
name?: string
deleted?: boolean
traits?: string[]
tenant?: UUID
creationUser?: UUID
modificationUser?: UUID
constructor (src?: Item) {
if (src) {
this.id = src.id
this.version = src.version
this.type = src.type
this._meta = src._meta
this.name = src.name
this.deleted = src.deleted
this.traits = src.traits
this.tenant = src.tenant
this.creationUser = src.creationUser
this.modificationUser = src.modificationUser
}
}
}
export class GenericItem extends Item {
[key: string]: any;
[key: string]: any;
}
export function OzoneType(typeIdentifier:string) {
return function <T extends {new(...args:any[]):{}}>(constructor:T) {
return class extends constructor {
type = typeIdentifier
}
}
/**
* Decorator for class that extend ozone item
* @param typeIdentifier
* @constructor
*/
export function OzoneType(typeIdentifier: string) {
return function <T extends {new(...args: any[]): {}}>(constructor: T) {
return class extends constructor {
type = typeIdentifier
}
}
}

@@ -570,3 +570,1 @@ export * from './AdminPermission';

export * from './WildcardQuery';
export type UUID = string
{
"name": "ozone-type",
"version": "5.3.0",
"version": "5.4.0",
"publishConfig": {

@@ -21,3 +21,3 @@ "access": "public"

"license": "ISC",
"gitHead": "efb9950fcea52e015a0a316915a21e58481cf2f2"
"gitHead": "ad81f40c3a71323098a7b18c65e07edf394aed94"
}
[![NPM version][npm-image]][npm-url]
# ozone-type
ozone type, Extracted from swagger
Expose Ozone and Flowr types in typescript

@@ -11,23 +11,72 @@ ## Install

```
## Utilities
## update ozone typings
* `Item`: base type for ozone items.
* `OzoneType`: decorator for class that extend Item.
* `FromOzone<T extends Item>`: template type for Item received from ozone.
* `function toPatch<T extends Item>(item: FromOzone<T>): Patch<T>`: transform Item received from ozone to item that can be saved.
* `function toPatchWithUndefinedAsNull<T extends Item>(item: FromOzone<T>): Patch<T>`: same as function toPatch but it set filed explicitly undefined to null so that they can be erase on ozone
This is a two-step process. First generate code using swagger-codegen:
Usage example
```typescript
import { toPatch, Patch, UUID, FromOzone } from 'ozone-type'
declare function getMyNewTypeFromOzone(id: UUID): FromOzone<MyNewType>
declare function saveMyNewTypeToOzone(data: Patch<MyNewType>): FromOzone<MyNewType>
const myData = getMyNewTypeFromOzone('myID')
const myDataToUpdate = toPatch(myData)
myDataToUpdate.aLocalizedAttr = {
fr: 'bonjour',
en: 'hello'
}
saveMyNewTypeToOzone(myDataToUpdate)
```
swagger-codegen generate -i swagger.json -l typescript-angular2 -o ozone
```
Then generate Ozone Item classes using oz. For example:
## Add one type
Add a file in ozone/model
````typeScript
// import base type
import { OzoneType, Item, UUID } from 'ozone-type'
/**
* MyNewType is a new ozone object
*/
OzoneType('my.new.type') // decorate to set type by default
export class MyNewType extends Item { // All the dynamic typed ozone object extend Item
anAttribute?: UUID
aLocalizedAttr?: {[key: string]: string}
/**
* Recopy constructor
* @param src
*/
constructor(src: MyNewType) {
super(src)
this.anAttribute = src.anAttribute
this.aLocalizedAttr = src.aLocalizedAttr
}
// Use static method for helpers. So that new is not mandatory.
static getAttrIn(src: MyNewType, language: string): string | undefined {
src.aLocalizedAttr = src.aLocalizedAttr || {}
return src.aLocalizedAttr[language]
}
}
````
Then add export statment in ozone/model/models.ts
## Bulck Update all ozone typings
Generate Ozone Item classes using oz. For example:
```
oz -u taktik -s https://test.flowr.cloud/ozone -p <password> generate --package "" --target typescript -o ./ozone-components/packages/ozone-helper/ozone-type/ozone/model
```
tsc
Then commit
git add ozone/model/*
[npm-image]: https://badge.fury.io/js/ozone-type.svg
[npm-url]: https://npmjs.org/package/ozone-type
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