├── .github
├── ISSUE_TEMPLATE
│ ├── discussion.md
│ └── issue.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── COPYING
├── CopyrightWaivers.txt
├── LICENSE
├── package.json
├── readme.md
├── tallbag.png
├── types.d.ts
└── usage.md
/.github/ISSUE_TEMPLATE/discussion.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Discussion
3 | about: Feel free to talk about any Tallbag-related topic!
4 |
5 | ---
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/issue.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Issue
3 | about: Report an inconsistency or logical hole in the Tallbag Specification
4 |
5 | ---
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules
2 | /ignore
3 | pnpm-lock.yaml
4 | package-lock.json
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | Creative Commons Legal Code
2 |
3 | CC0 1.0 Universal
4 |
5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12 | HEREUNDER.
13 |
14 | Statement of Purpose
15 |
16 | The laws of most jurisdictions throughout the world automatically confer
17 | exclusive Copyright and Related Rights (defined below) upon the creator
18 | and subsequent owner(s) (each and all, an "owner") of an original work of
19 | authorship and/or a database (each, a "Work").
20 |
21 | Certain owners wish to permanently relinquish those rights to a Work for
22 | the purpose of contributing to a commons of creative, cultural and
23 | scientific works ("Commons") that the public can reliably and without fear
24 | of later claims of infringement build upon, modify, incorporate in other
25 | works, reuse and redistribute as freely as possible in any form whatsoever
26 | and for any purposes, including without limitation commercial purposes.
27 | These owners may contribute to the Commons to promote the ideal of a free
28 | culture and the further production of creative, cultural and scientific
29 | works, or to gain reputation or greater distribution for their Work in
30 | part through the use and efforts of others.
31 |
32 | For these and/or other purposes and motivations, and without any
33 | expectation of additional consideration or compensation, the person
34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35 | is an owner of Copyright and Related Rights in the Work, voluntarily
36 | elects to apply CC0 to the Work and publicly distribute the Work under its
37 | terms, with knowledge of his or her Copyright and Related Rights in the
38 | Work and the meaning and intended legal effect of CC0 on those rights.
39 |
40 | 1. Copyright and Related Rights. A Work made available under CC0 may be
41 | protected by copyright and related or neighboring rights ("Copyright and
42 | Related Rights"). Copyright and Related Rights include, but are not
43 | limited to, the following:
44 |
45 | i. the right to reproduce, adapt, distribute, perform, display,
46 | communicate, and translate a Work;
47 | ii. moral rights retained by the original author(s) and/or performer(s);
48 | iii. publicity and privacy rights pertaining to a person's image or
49 | likeness depicted in a Work;
50 | iv. rights protecting against unfair competition in regards to a Work,
51 | subject to the limitations in paragraph 4(a), below;
52 | v. rights protecting the extraction, dissemination, use and reuse of data
53 | in a Work;
54 | vi. database rights (such as those arising under Directive 96/9/EC of the
55 | European Parliament and of the Council of 11 March 1996 on the legal
56 | protection of databases, and under any national implementation
57 | thereof, including any amended or successor version of such
58 | directive); and
59 | vii. other similar, equivalent or corresponding rights throughout the
60 | world based on applicable law or treaty, and any national
61 | implementations thereof.
62 |
63 | 2. Waiver. To the greatest extent permitted by, but not in contravention
64 | of, applicable law, Affirmer hereby overtly, fully, permanently,
65 | irrevocably and unconditionally waives, abandons, and surrenders all of
66 | Affirmer's Copyright and Related Rights and associated claims and causes
67 | of action, whether now known or unknown (including existing as well as
68 | future claims and causes of action), in the Work (i) in all territories
69 | worldwide, (ii) for the maximum duration provided by applicable law or
70 | treaty (including future time extensions), (iii) in any current or future
71 | medium and for any number of copies, and (iv) for any purpose whatsoever,
72 | including without limitation commercial, advertising or promotional
73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74 | member of the public at large and to the detriment of Affirmer's heirs and
75 | successors, fully intending that such Waiver shall not be subject to
76 | revocation, rescission, cancellation, termination, or any other legal or
77 | equitable action to disrupt the quiet enjoyment of the Work by the public
78 | as contemplated by Affirmer's express Statement of Purpose.
79 |
80 | 3. Public License Fallback. Should any part of the Waiver for any reason
81 | be judged legally invalid or ineffective under applicable law, then the
82 | Waiver shall be preserved to the maximum extent permitted taking into
83 | account Affirmer's express Statement of Purpose. In addition, to the
84 | extent the Waiver is so judged Affirmer hereby grants to each affected
85 | person a royalty-free, non transferable, non sublicensable, non exclusive,
86 | irrevocable and unconditional license to exercise Affirmer's Copyright and
87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the
88 | maximum duration provided by applicable law or treaty (including future
89 | time extensions), (iii) in any current or future medium and for any number
90 | of copies, and (iv) for any purpose whatsoever, including without
91 | limitation commercial, advertising or promotional purposes (the
92 | "License"). The License shall be deemed effective as of the date CC0 was
93 | applied by Affirmer to the Work. Should any part of the License for any
94 | reason be judged legally invalid or ineffective under applicable law, such
95 | partial invalidity or ineffectiveness shall not invalidate the remainder
96 | of the License, and in such case Affirmer hereby affirms that he or she
97 | will not (i) exercise any of his or her remaining Copyright and Related
98 | Rights in the Work or (ii) assert any associated claims and causes of
99 | action with respect to the Work, in either case contrary to Affirmer's
100 | express Statement of Purpose.
101 |
102 | 4. Limitations and Disclaimers.
103 |
104 | a. No trademark or patent rights held by Affirmer are waived, abandoned,
105 | surrendered, licensed or otherwise affected by this document.
106 | b. Affirmer offers the Work as-is and makes no representations or
107 | warranties of any kind concerning the Work, express, implied,
108 | statutory or otherwise, including without limitation warranties of
109 | title, merchantability, fitness for a particular purpose, non
110 | infringement, or the absence of latent or other defects, accuracy, or
111 | the present or absence of errors, whether or not discoverable, all to
112 | the greatest extent permissible under applicable law.
113 | c. Affirmer disclaims responsibility for clearing rights of other persons
114 | that may apply to the Work or any use thereof, including without
115 | limitation any person's Copyright and Related Rights in the Work.
116 | Further, Affirmer disclaims responsibility for obtaining any necessary
117 | consents, permissions or other rights required for any use of the
118 | Work.
119 | d. Affirmer understands and acknowledges that Creative Commons is not a
120 | party to this document and has no duty or obligation with respect to
121 | this CC0 or use of the Work.
--------------------------------------------------------------------------------
/CopyrightWaivers.txt:
--------------------------------------------------------------------------------
1 | Copyright Statement for Contributions to the Tallbag Standard
2 | =============================================================
3 |
4 | I hereby represent that all present, past and future contributions I make to
5 | the Tallbag project (which is the repository at callbag/tallbag on GitHub) are
6 | governed by the Creative Commons Zero 1.0 Universal copyright statement, placing
7 | my contributions in the public domain. This entails that to the extent possible
8 | under law I waive all copyright and related or neighboring rights to the code or
9 | documents I contribute. I also represent that I have the authority to perform
10 | the above waiver with respect to the entirety of my contributions.
11 |
12 | The text of the copyright statement is included in the COPYING file at the root
13 | of the Tallbag repository at
14 | https://github.com/callbag/tallbag/blob/master/COPYING.
15 |
16 | Underwriting parties:
17 |
18 | GitHub username| Real Name, Email Address used for git, Company (optional)
19 | ---------------+----------------------------------------------------------------
20 | staltz | Andre Medeiros, andre@staltz.com
21 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Licensed under Public Domain (CC0)
2 |
3 | To the extent possible under law, the person who associated CC0 with
4 | this code has waived all copyright and related or neighboring
5 | rights to this code.
6 |
7 | You should have received a copy of the CC0 legalcode along with this
8 | work. If not, see .
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "tallbag",
3 | "version": "1.2.0",
4 | "description": "Extension of the Callbag spec to add operator metadata",
5 | "repository": {
6 | "type": "git",
7 | "url": "git+https://github.com/callbag/tallbag.git"
8 | },
9 | "main": "index.js",
10 | "types": "types.d.ts",
11 | "author": "PUBLIC",
12 | "license": "CC0",
13 | "keywords": [
14 | "callbag",
15 | "tallbag",
16 | "callback",
17 | "standard",
18 | "spec",
19 | "observable",
20 | "iterable"
21 | ],
22 | "dependencies": {
23 | "callbag": "1.2.0"
24 | },
25 | "devDependencies": {
26 | "ts-node": "^4.1.0",
27 | "typescript": "3.2.x"
28 | }
29 | }
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Tallbag
2 |
3 | > A Callbag-compatible spec that adds introspection data
4 |
5 | 
6 |
7 | * Functionally the same as callbags
8 | * Tallbags can interoperate with callbags, and vice-versa
9 | * Tallbags deliver **data**, but also generate **shadow callbags** which deliver **metadata**
10 |
11 | The motivation for Tallbag is to provide a mechanism for creating and delivering metadata concerning any chain of Callbag operators. Such metadata can then be used by (visual) developer tools, for instance to display a graph of the chain of operators.
12 |
13 | Because it seemed unlikely that plain callbags could support delivering metadata, a new spec was created. However, this has very few differences with Callbag, and is fully compatible with Callbag.
14 |
15 | To see an example of what tallbags can achieve, check out this [static renderer of the chain operators](https://github.com/staltz/tallbag-for-each-poc-static-graph). Different and more robust renderers could be created.
16 |
17 | **[READ HERE HOW TO USE TALLBAGS](./usage.md)**
18 |
19 | ## Summary
20 |
21 | * Upon greeting, tallbags accept a 3rd (optional) argument: a shadow callbag
22 | * Shadow callbags are regular callbag sources that deliver metadata about the chain of tallbags
23 | * Every tallbag is a callbag
24 | * Every callbag works as a tallbag (where the third greeting argument is missing)
25 |
26 | ## Specification
27 |
28 | **`(type: number, payload?: any, shadow?: Callbag) => void`**
29 |
30 | ### Definitions
31 |
32 | - *Tallbag*: a function of signature (TypeScript syntax:) `(type: 0 | 1 | 2, payload?: any) => void`
33 | - *Greet*: if a tallbag is called with `0` as the first argument, we say "the tallbag is greeted", while the code which performed the call "greets the tallbag"
34 | - *Deliver*: if a tallbag is called with `1` as the first argument, we say "the tallbag is delivered data", while the code which performed the call "delivers data to the tallbag"
35 | - *Terminate*: if a tallbag is called with `2` as the first argument, we say "the tallbag is terminated", while the code which performed the call "terminates the tallbag"
36 | - *Source*: a tallbag which is expected to deliver data
37 | - *Sink*: a tallbag which is expected to be delivered data
38 |
39 | ### Protocol
40 |
41 | The capitalized keywords used here follow [IETF's RFC 2119](https://www.ietf.org/rfc/rfc2119.txt).
42 |
43 | **Greets**: `(type: 0, cb: Tallbag, shadow?: Callbag) => void`
44 |
45 | A tallbag is *greeted* when the first argument is `0` and the second argument is another tallbag (a function). **The third argument is an optional callbag, known as the _shadow callbag_.**
46 |
47 | **Handshake**
48 |
49 | When a source is greeted and given a sink as payload, the sink MUST be greeted back with a tallbag payload that is either the source itself or another tallbag (known as the "talkback"). In other words, greets are mutual. Reciprocal greeting is called a *handshake*.
50 |
51 | **Termination**: `(type: 2, err?: any) => void`
52 |
53 | A tallbag is *terminated* when the first argument is `2` and the second argument is either undefined (signalling termination due to success) or any truthy value (signalling termination due to failure).
54 |
55 | After the handshake, the source MAY terminate the sink. Alternatively, the sink MAY terminate the source after the handshake has occurred. If the source terminates the sink, then the sink SHOULD NOT terminate the source, and vice-versa. In other words, termination SHOULD NOT be mutual.
56 |
57 | **Data delivery** `(type: 1, data: any) => void`
58 |
59 | Amount of deliveries:
60 |
61 | - A tallbag (either sink or source) MAY be delivered data, once or multiple times
62 |
63 | Window of valid deliveries:
64 |
65 | - A tallbag MUST NOT be delivered data before it has been greeted
66 | - A tallbag MUST NOT be delivered data after it has been terminated
67 | - A sink MUST NOT be delivered data after it terminates its source
68 |
69 | **Reserved codes**
70 |
71 | A tallbag SHOULD NOT be called with any of these numbers as the first argument: `3`, `4`, `5`, `6`, `7`, `8`, `9`. Those are called *reserved codes*. A tallbag MAY be called with codes other than those in the range `[0-9]`, but this specification makes no claims in those cases.
72 |
73 | ## Legal
74 |
75 | This project is offered to the Public Domain in order to allow free use by interested parties who want to create compatible implementations. For details see `COPYING` and `CopyrightWaivers.txt`.
76 |
77 |
78 |
79 |
80 |
81 |
82 | To the extent possible under law,
83 |
84 | Tallbag Standard Special Interest Group
85 | has waived all copyright and related or neighboring rights to
86 | Tallbag Standard.
87 | This work is published from:
88 | Finland.
89 |
90 |
--------------------------------------------------------------------------------
/tallbag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/callbag/tallbag/3f5a5abef8946c124505efd51b20a961bba23e9f/tallbag.png
--------------------------------------------------------------------------------
/types.d.ts:
--------------------------------------------------------------------------------
1 | import {Callbag} from 'callbag';
2 |
3 | export type START = 0;
4 | export type DATA = 1;
5 | export type END = 2;
6 | export type RESERVED_3 = 3;
7 | export type RESERVED_4 = 4;
8 | export type RESERVED_5 = 5;
9 | export type RESERVED_6 = 6;
10 | export type RESERVED_7 = 7;
11 | export type RESERVED_8 = 8;
12 | export type RESERVED_9 = 9;
13 |
14 | /**
15 | * A Tallbag dynamically receives input of type I
16 | * and dynamically delivers output of type O
17 | */
18 | export type Tallbag = {
19 | (t: START, d: Tallbag, s?: Callbag): void;
20 | (t: DATA, d: I): void;
21 | (t: END, d?: any): void;
22 | };
23 |
24 | /**
25 | * A source only delivers data
26 | */
27 | export type Source = Tallbag;
28 |
29 | /**
30 | * A sink only receives data
31 | */
32 | export type Sink = Tallbag;
33 |
34 | export type SourceFactory = (...args: Array) => Source;
35 |
36 | export type SourceOperator = (
37 | ...args: Array
38 | ) => (source: Source) => Source;
39 |
40 | /**
41 | * Conditional types for contained type retrieval
42 | */
43 | export type UnwrapSource> = T extends Source<
44 | infer R,
45 | any
46 | >
47 | ? R
48 | : never;
49 | export type UnwrapSink> = T extends Sink
50 | ? R
51 | : never;
52 |
--------------------------------------------------------------------------------
/usage.md:
--------------------------------------------------------------------------------
1 | # Usage
2 |
3 | ## How to use tallbags
4 |
5 | When running in production, tallbags are exactly the same as callbags, both in behavior and in usage. The only practical difference is that the imports may change.
6 |
7 | ```diff
8 | -const {forEach, interval, map, filter, take, pipe} = require('callbag-basics');
9 | +const {forEach, interval, map, filter, take, pipe} = require('tallbag-basics');
10 |
11 | pipe(
12 | interval(1000),
13 | map(x => x + 1),
14 | filter(x => x % 2),
15 | take(5),
16 | forEach(x => console.log(x))
17 | );
18 | ```
19 |
20 | When running in development, tallbags produce data for developer tools, which can help you debug your code. That's how easy it is to use tallbags, if you're already familiar with callbags.
21 |
22 | ## Mixing callbags and tallbags
23 |
24 | You can also mix and match callbag libraries with tallbags libraries, in production there should be no visible difference. The code below works as you would expect:
25 |
26 | ```diff
27 | const {forEach, interval, map, take, pipe} = require('callbag-basics');
28 | +const filter = require('tallbag-filter');
29 |
30 | pipe(
31 | interval(1000),
32 | map(x => x + 1),
33 | + filter(x => x % 2),
34 | take(5),
35 | forEach(x => console.log(x))
36 | );
37 | ```
38 |
39 | When running in development, the devtools that depend on metadata from the tallbags will be missing data for every callbag that was included. That's the only downside of mixing these two.
40 |
41 | ## How to create Tallbag libraries
42 |
43 | A shadow callbag can be (according to the Tallbag spec) any callbag, but in practice most libraries should use a default shadow implementation which collects operator chain metadata as JSON. This is what the module `shadow-callbag` is for. It comes with one utility: `makeShadow()`.
44 |
45 | When implementing a Tallbag library, it's useful to start from a Callbag library implementation, and adapt it. You could do this as fork. The implementation is slightly different for operators and for factories (creation operators).
46 |
47 | ### Source factories
48 |
49 | To add a shadow callbag to a source factory (a.k.a. creation operator):
50 |
51 | - Import/require `makeShadow` from `shadow-callbag`
52 | - In the source factory, create `const shadow = makeShadow('my-library')`
53 | - When your source greets the sink, pass the `shadow` as the 3rd argument
54 | - Whenever the source is going to deliver data to the sink, also deliver that same data to the shadow: `shadow(1, data)`
55 |
56 | See example below, where we convert `callbag-interval` to `tallbag-interval`:
57 |
58 | ```diff
59 | +const makeShadow = require('shadow-callbag').default;
60 |
61 | const interval = period => (start, sink) => {
62 | if (start !== 0) return;
63 | let i = 0;
64 | + const shadow = makeShadow('interval');
65 | const id = setInterval(() => {
66 | + shadow(1, i);
67 | sink(1, i);
68 | i++;
69 | }, period);
70 | function talkback(t) {
71 | if (t === 2) clearInterval(id);
72 | }
73 | - sink(0, talkback);
74 | + sink(0, talkback, shadow);
75 | };
76 | ```
77 |
78 | ### Operators
79 |
80 | Adding a shadow callbag to an tallbag operator is similar to source factories, but this time you have to handle **two shadows**: the shadow coming from above, and the shadow to be given downwards.
81 |
82 | - Import/require `makeShadow` from `shadow-callbag`
83 | - When the source greets the operator, create `const shadow = makeShadow('my-library', shadowFromAbove)`
84 | - When the operator greets the sink, pass the `shadow` as the 3rd argument
85 | - Whenever the operator is going to deliver data to the sink, also deliver that same data to the shadow: `shadow(1, data)`
86 |
87 | In the example below, we convert `callbag-filter` to `tallbag-filter`. The shadow coming from above is `s`, and the shadow sent downwards is `shadow`.
88 |
89 | ```diff
90 | +const makeShadow = require('shadow-callbag').default;
91 |
92 | const filter = condition => source => (start, sink) => {
93 | if (start !== 0) return;
94 | let talkback;
95 | - source(0, (t, d) => {
96 | + let shadow;
97 | + source(0, (t, d, s) => {
98 | if (t === 0) {
99 | + shadow = makeShadow('filter', s);
100 | talkback = d;
101 | - sink(0, talkback);
102 | + sink(0, talkback, shadow);
103 | } else if (t === 1) {
104 | - if (condition(d)) sink(t, d);
105 | + if (condition(d)) {
106 | + shadow(t, d);
107 | + sink(t, d);
108 | + }
109 | else talkback(1);
110 | }
111 | else sink(t, d);
112 | });
113 | };
114 | ```
115 |
--------------------------------------------------------------------------------