Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2977 #3798

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,962 changes: 4,962 additions & 0 deletions packages/metadata-protobuf/compiled/index.d.ts

Large diffs are not rendered by default.

12,109 changes: 12,109 additions & 0 deletions packages/metadata-protobuf/compiled/index.js

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions packages/metadata-protobuf/lib/KnownLicenses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{
"code": 1000,
"name": "CUSTOM",
"longName": "Custom License",
"description": "A user defined License",
"url": "",
"attributionRequired": false
},
{
"code": 1001,
"name": "PDM",
"longName": "Public Domain",
"description": "For items which are not protected by copyright. This is not a license, but rather a copyright status. Some government-produced works, items with expired copyrights, and those which are ineligible for copyright protection may be included in this category.",
"url": "https://creativecommons.org/share-your-work/public-domain/pdm",
"attributionRequired": false
},
{
"code": 1002,
"name": "CC0",
"longName": "Public Domain Dedication",
"description": "The CC0 (Public Domain Dedication) License allows creators to waive all rights to their creations and release them into the Public Domain.",
"url": "https://creativecommons.org/share-your-work/public-domain/cc0",
"attributionRequired": true
},
{
"code": 1003,
"name": "CC_BY",
"longName": "Creative Commons Attribution License",
"description": "Sharing and adapting this content is permitted, but attribution must be provided. Read the License Deed for more information.",
"url": "https://creativecommons.org/licenses/by/4.0",
"attributionRequired": true
},
{
"code": 1004,
"name": "CC_BY_SA",
"longName": "Creative Commons Attribution-ShareAlike License",
"description": "Sharing and adapting this content is permitted, but attribution must be provided. Any derivative works must be distributed under the same license. Read the License Deed for more information.",
"url": "https://creativecommons.org/licenses/by-sa/4.0",
"attributionRequired": true
},
{
"code": 1005,
"name": "CC_BY_ND",
"longName": "Creative Commons Attribution-NoDerivs License",
"description": "Sharing this content is permitted, but attribution must be provided. You may not remix, transform, or build upon the material. Read the License Deed for more information.",
"url": "https://creativecommons.org/licenses/by-nd/4.0",
"attributionRequired": true
},
{
"code": 1006,
"name": "CC_BY_NC",
"longName": "Creative Commons Attribution-NonCommercial License",
"description": "Sharing and adapting this content is permitted, but attribution must be provided. Commercial use is not permitted. Read the License Deed for more information.",
"url": "https://creativecommons.org/licenses/by-nc/4.0",
"attributionRequired": true
},
{
"code": 1007,
"name": "CC_BY_NC_SA",
"longName": "Creative Commons Attribution-NonCommercial-ShareAlike License",
"description": "Sharing and adapting this content is permitted, but attribution must be provided. Any derivative works must be distributed under the same license. Commercial use is not permitted. Read the License Deed for more information.",
"url": "https://creativecommons.org/licenses/by-nc-sa/4.0",
"attributionRequired": true
},
{
"code": 1008,
"name": "CC_BY_NC_ND",
"longName": "Creative Commons Attribution-NonCommercial-NoDerivs License",
"description": "Sharing this content is permitted, but attribution must be provided. You may not remix, transform, or build upon the material. Commercial use is not permitted. Read the License Deed for more information.",
"url": "https://creativecommons.org/licenses/by-nc-nd/4.0",
"attributionRequired": true
}
]
1 change: 1 addition & 0 deletions packages/metadata-protobuf/lib/consts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const MAX_TAGS_PER_FORUM_THREAD = 5;
4 changes: 4 additions & 0 deletions packages/metadata-protobuf/lib/consts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MAX_TAGS_PER_FORUM_THREAD = void 0;
exports.MAX_TAGS_PER_FORUM_THREAD = 5;
1 change: 1 addition & 0 deletions packages/metadata-protobuf/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../compiled';
14 changes: 14 additions & 0 deletions packages/metadata-protobuf/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
// protobuf message constructors
__exportStar(require("../compiled"), exports);
23 changes: 23 additions & 0 deletions packages/metadata-protobuf/lib/licenses.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { License } from '../compiled/index';
export declare type LicenseCode = number;
export declare const CUSTOM_LICENSE_CODE: LicenseCode;
declare type KnownLicense = {
code: LicenseCode;
name: string;
longName: string;
description: string;
url: string;
attributionRequired: boolean;
};
export declare const KnownLicenses: Map<number, KnownLicense>;
export declare function getLicenseCodeByName(name: string): LicenseCode | undefined;
export declare function createKnownLicenseFromCode(code: LicenseCode, attribution?: string): License;
export declare function createCustomKnownLicense(customText: string): License;
declare const _default: {
CUSTOM_LICENSE_CODE: number;
KnownLicenses: Map<number, KnownLicense>;
createCustomKnownLicense: typeof createCustomKnownLicense;
createKnownLicenseFromCode: typeof createKnownLicenseFromCode;
getLicenseCodeByName: typeof getLicenseCodeByName;
};
export default _default;
51 changes: 51 additions & 0 deletions packages/metadata-protobuf/lib/licenses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use strict";
// Helper methods to handle joystream defined license types
// This should be factored out into a separate package
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCustomKnownLicense = exports.createKnownLicenseFromCode = exports.getLicenseCodeByName = exports.KnownLicenses = exports.CUSTOM_LICENSE_CODE = void 0;
const KnownLicenses_json_1 = __importDefault(require("./KnownLicenses.json"));
const index_1 = require("../compiled/index");
exports.CUSTOM_LICENSE_CODE = 1000;
exports.KnownLicenses = new Map();
KnownLicenses_json_1.default.forEach((license) => {
exports.KnownLicenses.set(license.code, license);
});
function getLicenseCodeByName(name) {
for (const [code, license] of exports.KnownLicenses) {
if (license.name === name)
return code;
}
}
exports.getLicenseCodeByName = getLicenseCodeByName;
function createKnownLicenseFromCode(code, attribution) {
if (code === exports.CUSTOM_LICENSE_CODE) {
throw new Error('Use createCustomLicense() instead');
}
const knownLicense = exports.KnownLicenses.get(code);
if (!knownLicense) {
throw new Error('Unknown License Code');
}
const license = new index_1.License({ code });
if (knownLicense.attributionRequired) {
if (attribution === undefined) {
throw new Error('Attribution required for selected license');
}
license.attribution = attribution;
}
return license;
}
exports.createKnownLicenseFromCode = createKnownLicenseFromCode;
function createCustomKnownLicense(customText) {
return new index_1.License({ code: exports.CUSTOM_LICENSE_CODE, customText });
}
exports.createCustomKnownLicense = createCustomKnownLicense;
exports.default = {
CUSTOM_LICENSE_CODE: exports.CUSTOM_LICENSE_CODE,
KnownLicenses: exports.KnownLicenses,
createCustomKnownLicense,
createKnownLicenseFromCode,
getLicenseCodeByName,
};
22 changes: 22 additions & 0 deletions packages/metadata-protobuf/lib/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Long } from 'long';
import { IConversionOptions } from 'protobufjs';
export declare type AnyMessage<T> = T & {
toJSON(): Record<string, unknown>;
};
export declare type AnyMetadataClass<T> = {
name: string;
decode(binary: Uint8Array): AnyMessage<T>;
encode(obj: T): {
finish(): Uint8Array;
};
toObject(obj: AnyMessage<T>, options?: IConversionOptions): Record<string, unknown>;
verify(message: {
[k: string]: unknown;
}): null | string;
fromObject(object: {
[k: string]: unknown;
}): AnyMessage<T>;
};
export declare type DecodedMetadataObject<T> = {
[K in keyof T]: T[K] extends Long | null | undefined ? Exclude<T[K], Long> | string : T[K] extends string | number | boolean | null | undefined ? T[K] : T[K] extends Array<infer S> ? DecodedMetadataObject<S>[] : DecodedMetadataObject<T[K]>;
};
2 changes: 2 additions & 0 deletions packages/metadata-protobuf/lib/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
11 changes: 11 additions & 0 deletions packages/metadata-protobuf/lib/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AnyMessage, AnyMetadataClass, DecodedMetadataObject } from './types';
export declare function isSet<T>(v: T | null | undefined): v is T;
export declare function isEmptyObject<T>(object: T): boolean;
export declare function integrateMeta<T, Props extends readonly (keyof T & keyof M & string)[], M extends {
[K in Props[number]]?: T[K] | null;
}>(object: T, meta: M, props: Props): void;
export declare function encodeDecode<T>(metaClass: AnyMetadataClass<T>, value: T): DecodedMetadataObject<T>;
export declare function metaToObject<T>(metaClass: AnyMetadataClass<T>, value: AnyMessage<T>): DecodedMetadataObject<T>;
export declare function isValidCountryCode(code: string): boolean;
export declare function isValidLanguageCode(code: string): boolean;
export declare function isValidSubdivisionCode(code: string): boolean;
51 changes: 51 additions & 0 deletions packages/metadata-protobuf/lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidSubdivisionCode = exports.isValidLanguageCode = exports.isValidCountryCode = exports.metaToObject = exports.encodeDecode = exports.integrateMeta = exports.isEmptyObject = exports.isSet = void 0;
const i18n_iso_countries_1 = __importDefault(require("i18n-iso-countries"));
const iso_639_1_1 = __importDefault(require("iso-639-1"));
const iso_3166_2_1 = __importDefault(require("iso-3166-2"));
function isSet(v) {
return v !== null && v !== undefined;
}
exports.isSet = isSet;
function isEmptyObject(object) {
return Object.keys(object).length === 0;
}
exports.isEmptyObject = isEmptyObject;
function integrateMeta(object, meta, props) {
props.forEach((prop) => {
const metaPropVal = meta[prop];
if (isSet(metaPropVal)) {
object[prop] = metaPropVal;
}
});
}
exports.integrateMeta = integrateMeta;
function encodeDecode(metaClass, value) {
const encoded = metaClass.encode(value).finish();
return metaToObject(metaClass, metaClass.decode(encoded));
}
exports.encodeDecode = encodeDecode;
function metaToObject(metaClass, value) {
// Default conversion options - use Strings for "Long" values and ignore unset "repeated" fields
return metaClass.toObject(value, { arrays: false, longs: String });
}
exports.metaToObject = metaToObject;
// Checks if the provided code is valid according to ISO 3166-1 alpha-2 standard
function isValidCountryCode(code) {
return i18n_iso_countries_1.default.getAlpha2Codes()[code] !== undefined;
}
exports.isValidCountryCode = isValidCountryCode;
// Checks if the provided code is valid according to ISO 639-1 standard
function isValidLanguageCode(code) {
return iso_639_1_1.default.validate(code);
}
exports.isValidLanguageCode = isValidLanguageCode;
// According to ISO 3166-2 standard
function isValidSubdivisionCode(code) {
return !!iso_3166_2_1.default.subdivision(code);
}
exports.isValidSubdivisionCode = isValidSubdivisionCode;
Loading