-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update build process to release as an ES2015 library with type declar…
…ations (#6) * Update build process to release as an ES5 library with type declarations. * Add lib directory with output
- Loading branch information
1 parent
d0650bc
commit a05e3a6
Showing
42 changed files
with
970 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
dist/ | ||
.tmp/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface AttributeOptions { | ||
name?: string; | ||
} | ||
export declare function attribute(options?: AttributeOptions): PropertyDecorator; | ||
export declare type AttributeMetadata = { | ||
[name: string]: AttributeOptions; | ||
}; | ||
export declare function getAttributeMetadata(target: any): AttributeMetadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metadata_map_1 = require("./metadata-map"); | ||
var ATTRIBUTES_MAP = new metadata_map_1.MetadataMap(); | ||
function attribute(options) { | ||
var opts = options || {}; | ||
return function (target, key) { | ||
ATTRIBUTES_MAP.setMetadataByType(target.constructor.name, key, Object.assign({ | ||
name: key, | ||
}, opts)); | ||
}; | ||
} | ||
exports.attribute = attribute; | ||
function getAttributeMetadata(target) { | ||
return ATTRIBUTES_MAP.getMetadataByType(target.name); | ||
} | ||
exports.getAttributeMetadata = getAttributeMetadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ResourceIdentifier } from '../jsonapi'; | ||
export interface ResourceIdentifierConstructor { | ||
new (): ResourceIdentifier; | ||
} | ||
export declare class TypeMap { | ||
private constructorsByJsonapiType; | ||
get(typeName: string): ResourceIdentifierConstructor; | ||
set(typeName: string, constructorType: ResourceIdentifierConstructor): void; | ||
} | ||
export declare const ENTITIES_MAP: TypeMap; | ||
export declare function getClassForJsonapiType(type: string): ResourceIdentifierConstructor; | ||
export declare function getConstructorForJsonapiType(type: string): Function; | ||
export interface EntityOptions { | ||
type: string; | ||
} | ||
/** | ||
* Annotates a class to indicate that it is a JSON:API entity definition. | ||
* | ||
* Any class annotated with `@entity` should be considered serialisable to JSON:API, | ||
* and should have `@attribute` and `@relationship` decorators to indicate properties | ||
* to be serialisable to and deserialisable from appropriate JSON:API data. | ||
* | ||
*/ | ||
export declare function entity(options: EntityOptions): (constructor: ResourceIdentifierConstructor) => any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var TypeMap = /** @class */ (function () { | ||
function TypeMap() { | ||
this.constructorsByJsonapiType = {}; | ||
} | ||
TypeMap.prototype.get = function (typeName) { | ||
return this.constructorsByJsonapiType[typeName]; | ||
}; | ||
TypeMap.prototype.set = function (typeName, constructorType) { | ||
this.constructorsByJsonapiType[typeName] = constructorType; | ||
}; | ||
return TypeMap; | ||
}()); | ||
exports.TypeMap = TypeMap; | ||
exports.ENTITIES_MAP = new TypeMap(); | ||
function getClassForJsonapiType(type) { | ||
return exports.ENTITIES_MAP.get(type); | ||
} | ||
exports.getClassForJsonapiType = getClassForJsonapiType; | ||
function getConstructorForJsonapiType(type) { | ||
var clazz = getClassForJsonapiType(type); | ||
return clazz && clazz.prototype && clazz.prototype.constructor; | ||
} | ||
exports.getConstructorForJsonapiType = getConstructorForJsonapiType; | ||
/** | ||
* Annotates a class to indicate that it is a JSON:API entity definition. | ||
* | ||
* Any class annotated with `@entity` should be considered serialisable to JSON:API, | ||
* and should have `@attribute` and `@relationship` decorators to indicate properties | ||
* to be serialisable to and deserialisable from appropriate JSON:API data. | ||
* | ||
*/ | ||
function entity(options) { | ||
var type = options.type; | ||
return function (constructor) { | ||
var original = constructor; | ||
// a utility function to generate instances of a class | ||
var construct = function (constructorFunc, args) { | ||
var constructorClosure = function () { | ||
return constructorFunc.apply(this, args); | ||
}; | ||
constructorClosure.prototype = constructorFunc.prototype; | ||
// construct an instance and bind "type" correctly | ||
var instance = new constructorClosure(); | ||
instance.type = type; | ||
return instance; | ||
}; | ||
// the new constructor behaviour | ||
var wrappedConstructor = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return construct(original, args); | ||
}; | ||
// copy prototype so intanceof operator still works | ||
wrappedConstructor.prototype = original.prototype; | ||
// add the type to the reverse lookup for deserialisation | ||
exports.ENTITIES_MAP.set(type, wrappedConstructor); | ||
// return new constructor (will override original) | ||
return wrappedConstructor; | ||
}; | ||
} | ||
exports.entity = entity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './attribute'; | ||
export * from './entity'; | ||
export * from './link'; | ||
export * from './meta'; | ||
export * from './relationship'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./attribute")); | ||
__export(require("./entity")); | ||
__export(require("./link")); | ||
__export(require("./meta")); | ||
__export(require("./relationship")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface LinkOptions { | ||
name?: string; | ||
} | ||
export declare function link(options?: LinkOptions): PropertyDecorator; | ||
export declare type LinkMetadata = { | ||
[name: string]: LinkOptions; | ||
}; | ||
export declare function getLinkMetadata(target: any): LinkMetadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metadata_map_1 = require("./metadata-map"); | ||
var LINKS_MAP = new metadata_map_1.MetadataMap(); | ||
function link(options) { | ||
var opts = options || {}; | ||
return function (target, key) { | ||
LINKS_MAP.setMetadataByType(target.constructor.name, key, Object.assign({ | ||
name: key, | ||
}, opts)); | ||
}; | ||
} | ||
exports.link = link; | ||
function getLinkMetadata(target) { | ||
return LINKS_MAP.getMetadataByType(target.name); | ||
} | ||
exports.getLinkMetadata = getLinkMetadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface MetaOptions { | ||
name?: string; | ||
} | ||
export declare function meta(options?: MetaOptions): PropertyDecorator; | ||
export declare type MetaMetadata = { | ||
[name: string]: MetaOptions; | ||
}; | ||
export declare function getMetaMetadata(target: any): MetaMetadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metadata_map_1 = require("./metadata-map"); | ||
var META_PROPERTIES_MAP = new metadata_map_1.MetadataMap(); | ||
function meta(options) { | ||
var opts = options || {}; | ||
return function (target, key) { | ||
META_PROPERTIES_MAP.setMetadataByType(target.constructor.name, key, Object.assign({ | ||
name: key, | ||
}, opts)); | ||
}; | ||
} | ||
exports.meta = meta; | ||
function getMetaMetadata(target) { | ||
return META_PROPERTIES_MAP.getMetadataByType(target.name); | ||
} | ||
exports.getMetaMetadata = getMetaMetadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export declare type MetadataByPropertyName<T> = { | ||
[attributeName: string]: T; | ||
}; | ||
export declare type PropertyTypesForType<T> = { | ||
[typeName: string]: MetadataByPropertyName<T>; | ||
}; | ||
export declare class MetadataMap<T> { | ||
private metadataByType; | ||
getMetadataByType(typeName: string): MetadataByPropertyName<T>; | ||
setMetadataByType(typeName: string, keyName: string, metadata: T): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var MetadataMap = /** @class */ (function () { | ||
function MetadataMap() { | ||
this.metadataByType = {}; | ||
} | ||
MetadataMap.prototype.getMetadataByType = function (typeName) { | ||
return this.metadataByType[typeName] || {}; | ||
}; | ||
MetadataMap.prototype.setMetadataByType = function (typeName, keyName, metadata) { | ||
this.metadataByType[typeName] = Object.assign({}, this.getMetadataByType(typeName), (_a = {}, | ||
_a[keyName] = metadata, | ||
_a)); | ||
var _a; | ||
}; | ||
return MetadataMap; | ||
}()); | ||
exports.MetadataMap = MetadataMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface RelationshipOptions { | ||
allowUnresolvedIdentifiers?: boolean; | ||
name?: string; | ||
} | ||
export declare function relationship(options?: RelationshipOptions): PropertyDecorator; | ||
export declare type RelationshipMetadata = { | ||
[name: string]: RelationshipOptions; | ||
}; | ||
export declare function getRelationshipMetadata(target: any): RelationshipMetadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metadata_map_1 = require("./metadata-map"); | ||
var RELATIONSHIPS_MAP = new metadata_map_1.MetadataMap(); | ||
var DefaultRelationshipOptions = { | ||
allowUnresolvedIdentifiers: false, | ||
}; | ||
function relationship(options) { | ||
var opts = Object.assign({}, DefaultRelationshipOptions, options || {}); | ||
return function (target, key) { | ||
RELATIONSHIPS_MAP.setMetadataByType(target.constructor.name, key, Object.assign({ | ||
name: key, | ||
}, opts)); | ||
}; | ||
} | ||
exports.relationship = relationship; | ||
function getRelationshipMetadata(target) { | ||
return RELATIONSHIPS_MAP.getMetadataByType(target.name); | ||
} | ||
exports.getRelationshipMetadata = getRelationshipMetadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './decorators'; | ||
export * from './jsonapi'; | ||
export * from './serialisation'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./decorators")); | ||
__export(require("./jsonapi")); | ||
__export(require("./serialisation")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './types'; | ||
export * from './unresolved-identifiers'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./types")); | ||
__export(require("./unresolved-identifiers")); |
Oops, something went wrong.