From adaad654ab71b3d3515a009681e8b6684c54c298 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Tue, 6 Dec 2016 15:05:39 +0000 Subject: [PATCH] Remove types for normalizr (#13129) --- normalizr/index.d.ts | 109 -------------- normalizr/normalizr-tests.ts | 270 ----------------------------------- normalizr/tsconfig.json | 19 --- notNeededPackages.json | 8 +- 4 files changed, 7 insertions(+), 399 deletions(-) delete mode 100644 normalizr/index.d.ts delete mode 100644 normalizr/normalizr-tests.ts delete mode 100644 normalizr/tsconfig.json diff --git a/normalizr/index.d.ts b/normalizr/index.d.ts deleted file mode 100644 index 144839b5e4e92c..00000000000000 --- a/normalizr/index.d.ts +++ /dev/null @@ -1,109 +0,0 @@ -// Type definitions for normalizr 2.0.1 -// Project: https://github.com/gaearon/normalizr/ -// Definitions by: Markus Peloso -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -export = Normalizr; - -declare namespace Normalizr { - type AttributeSetting = string | ((entity: any) => any); - - type SchemaClass = Schema | ArraySchema | UnionSchema; - - type SchemaObject = { [property: string]: SchemaClass | SchemaObject }; - - type SchemaType = SchemaClass | SchemaObject | Object; - - export class Schema { - /** - * Schema lets you define a type of entity returned by your API. - * This should correspond to model in your server code. - * @param key The key parameter lets you specify the name of the dictionary for this kind of entity. - * @param options - */ - constructor(key: string, options?: { idAttribute: AttributeSetting; }); - - /** - * Lets you specify relationships between different entities. - * @param nestedSchema - */ - define(nestedSchema: SchemaObject): void; - - /** - * Returns the key of the schema. - */ - getKey(): string; - - /** - * Returns the idAttribute of the schema. - */ - getIdAttribute(): AttributeSetting; - } - - interface UnionSchema { - getItemSchema(): SchemaType; - getSchemaKey(item: any): string; - } - - interface ArraySchema { - getItemSchema(): SchemaType; - } - - /** - * Describes an array of the schema passed as argument. - * @param schema - * @param options - */ - export function arrayOf(schema: SchemaType, options?: { - /** - * If the array contains entities with different schemas, you can use the schemaAttribute option to specify which schema to use for each entity. - */ - schemaAttribute: AttributeSetting - }): ArraySchema; - - /** - * Describes a map whose values follow the schema passed as argument. - * @param schema - * @param options - */ - export function valuesOf(schema: SchemaType, options?: { - /** - * If the map contains entities with different schemas, you can use the schemaAttribute option to specify which schema to use for each entity. - */ - schemaAttribute: AttributeSetting - }): ArraySchema; - - /** - * Describe a schema which is a union of multiple schemas. This is useful if you need the polymorphic behavior provided by arrayOf or valuesOf but for non-collection fields. - * @param schemaMap - * @param options - */ - export function unionOf(schemaMap: SchemaType, options?: { - /** - * Use the required schemaAttribute option to specify which schema to use for each entity. - */ - schemaAttribute: AttributeSetting - }): UnionSchema; - - /** - * Normalizes object according to schema. - * Passed schema should be a nested object reflecting the structure of API response. - * @param obj - * @param schema - * @param options - */ - export function normalize(obj: any | Array, schema: SchemaType, options?: { - /** - * This is useful if your backend emits additional fields, such as separate ID fields, you'd like to delete in the normalized entity. - */ - assignEntity?: (normalized: any, key: string, entity: any) => any; - - /** - * You can use this to resolve conflicts when merging entities with the same key. - */ - mergeIntoEntity?: (stored: any, normalized: any, entityKey: string) => any; - }): { - entities: any; - result: any; - }; -} diff --git a/normalizr/normalizr-tests.ts b/normalizr/normalizr-tests.ts deleted file mode 100644 index 7b39cb2fc88589..00000000000000 --- a/normalizr/normalizr-tests.ts +++ /dev/null @@ -1,270 +0,0 @@ - - -import { normalize, Schema, arrayOf, unionOf, valuesOf } from 'normalizr'; - -// First, define a schema for our entities: - -const article1 = new Schema('articles'); -const user1 = new Schema('users'); - -// Then we define nesting rules: - -article1.define({ - author: user1, - contributors: arrayOf(user1) -}); - -// Now we can use this schema in our API response handlers: - -const ServerActionCreators = { - // These are two different XHR endpoints with different response schemas. - // We can use the schema objects defined earlier to express both of them: - - receiveOneArticle(response: any) { - // Here, the response is an object containing data about one article. - // Passing the article schema as second parameter to normalize() lets it - // correctly traverse the response tree and gather all entities: - - // BEFORE: - // { - // id: 1, - // title: 'Some Article', - // author: { - // id: 7, - // name: 'Dan' - // }, - // contributors: [{ - // id: 10, - // name: 'Abe' - // }, { - // id: 15, - // name: 'Fred' - // }] - // } - // - // AFTER: - // { - // result: 1, // <--- Note object is referenced by ID - // entities: { - // articles: { - // 1: { - // author: 7, // <--- Same happens for references to - // contributors: [10, 15] // <--- other entities in the schema - // ...} - // }, - // users: { - // 7: { ... }, - // 10: { ... }, - // 15: { ... } - // } - // } - // } - - response = normalize(response, article1); - }, - - receiveAllArticles(response: any) { - // Here, the response is an object with the key 'articles' referencing - // an array of article objects. Passing { articles: arrayOf(article) } as - // second parameter to normalize() lets it correctly traverse the response - // tree and gather all entities: - - // BEFORE: - // { - // articles: [{ - // id: 1, - // title: 'Some Article', - // author: { - // id: 7, - // name: 'Dan' - // }, - // ... - // }, - // ... - // ] - // } - // - // AFTER: - // { - // result: { - // articles: [1, 2, ...] // <--- Note how object array turned into ID array - // }, - // entities: { - // articles: { - // 1: { author: 7, ... }, // <--- Same happens for references to other entities in the schema - // 2: { ... }, - // ... - // }, - // users: { - // 7: { ... }, - // .. - // } - // } - // } - - response = normalize(response, { - articles: arrayOf(article1) - }); - } -} - -// new Schema(key, [options]) - -const article2 = new Schema('articles'); - -// You can use a custom id attribute -const article3 = new Schema('articles', { idAttribute: 'slug' }); - -// Or you can specify a function to infer it -function generateSlug(entity: any) { /* ... */ } -const article4 = new Schema('articles', { idAttribute: generateSlug }); - -// Schema.prototype.define(nestedSchema) - -const article5 = new Schema('articles'); -const user5 = new Schema('users'); - -article5.define({ - author: user5 -}); - -// Schema.prototype.getKey() - -const article6 = new Schema('articles'); - -article6.getKey(); -// articles - -// Schema.prototype.getIdAttribute() - -const article7 = new Schema('articles'); -const slugArticle7 = new Schema('articles', { idAttribute: 'slug' }); - -article7.getIdAttribute(); -// id -slugArticle7.getIdAttribute(); -// slug - -// arrayOf(schema, [options]) - -const article8 = new Schema('articles'); -const user8 = new Schema('users'); - -article8.define({ - author: user8, - contributors: arrayOf(user8) -}); - -const article9 = new Schema('articles'); -const image9 = new Schema('images'); -const video9 = new Schema('videos'); -const asset9 = { - images: image9, - videos: video9 -}; - -// You can specify the name of the attribute that determines the schema -article9.define({ - assets: arrayOf(asset9, { schemaAttribute: 'type' }) -}); - -// Or you can specify a function to infer it -function inferSchema9(entity: any) { /* ... */ } -article9.define({ - assets: arrayOf(asset9, { schemaAttribute: inferSchema9 }) -}); - -// valuesOf(schema, [options]) - -const article10 = new Schema('articles'); -const user10 = new Schema('users'); - -article10.define({ - collaboratorsByRole: valuesOf(user10) -}); - -const article11 = new Schema('articles'); -const user11 = new Schema('users'); -const group11 = new Schema('groups'); -const collaborator11 = { - users: user11, - groups: group11 -}; - -// You can specify the name of the attribute that determines the schema -article11.define({ - collaboratorsByRole: valuesOf(collaborator11, { schemaAttribute: 'type' }) -}); - -// Or you can specify a function to infer it -function inferSchema11(entity: any) { /* ... */ } -article11.define({ - collaboratorsByRole: valuesOf(collaborator11, { schemaAttribute: inferSchema }) -}); - -// unionOf(schemaMap, [options]) - -const group12 = new Schema('groups'); -const user12 = new Schema('users'); - -// a member can be either a user or a group -const member12 = { - users: user12, - groups: group12 -}; - -// You can specify the name of the attribute that determines the schema -group12.define({ - owner: unionOf(member12, { schemaAttribute: 'type' }) -}); - -// Or you can specify a function to infer it -function inferSchema(entity: any) { /* ... */ } -group12.define({ - creator: unionOf(member12, { schemaAttribute: inferSchema }) -}); - -const group13 = new Schema('groups'); -const user13 = new Schema('users'); - -const member13 = unionOf({ - users: user13, - groups: group13 -}, { schemaAttribute: 'type' }); - -group13.define({ - owner: member13, - members: arrayOf(member13), - relationships: valuesOf(member13) -}); - -// normalize(obj, schema, [options]) - -const article14 = new Schema('articles'); -const user14 = new Schema('users'); - -article14.define({ - author: user14, - contributors: arrayOf(user14), - meta: { - likes: arrayOf({ - user: user14 - }) - } -}); - -// ... - -// Normalize one article object -const json = { id: 1, author: /*...*/{} }; -const normalized1 = normalize(json, article14); - -// Normalize an array of article objects -const arr = [{ id: 1, author: /*...*/{} }/*, ...*/] -const normalized2 = normalize(arr, arrayOf(article14)); - -// Normalize an array of article objects, referenced by an object key: -const wrappedArr = { articles: [{ id: 1, author: /*...*/{} }/*, ...*/] } -const normalized3 = normalize(wrappedArr, { - articles: arrayOf(article14) -}); diff --git a/normalizr/tsconfig.json b/normalizr/tsconfig.json deleted file mode 100644 index 88f6e543dc75bf..00000000000000 --- a/normalizr/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "target": "es6", - "noImplicitAny": true, - "strictNullChecks": false, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "normalizr-tests.ts" - ] -} \ No newline at end of file diff --git a/notNeededPackages.json b/notNeededPackages.json index 34c21d8acdab7f..d121004212d285 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -82,6 +82,12 @@ "typingsPackageName": "redux", "sourceRepoURL": "https://github.com/reactjs/redux", "asOfVersion": "3.6.0" + }, + { + "libraryName": "Normalizr", + "typingsPackageName": "normalizr", + "sourceRepoURL": "https://github.com/paularmstrong/normalizr", + "asOfVersion": "2.0.18" } ] -} \ No newline at end of file +}